From 8ba5340fb88fdfa01c8b55418c730cb9823f6a7c Mon Sep 17 00:00:00 2001 From: okuji Date: Thu, 25 May 2000 04:54:05 +0000 Subject: [PATCH] fix the bug in RRQ completely! --- ChangeLog | 7 +++++++ netboot/fsys_tftp.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index cf9ce41e6..e2f8be269 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2000-05-25 OKUJI Yoshinori + + * netboot/fsys_tftp.c (buf_fill): Warn when amazing things + happen. + (tftp_dir): Revert previous change. Don't use TFTP_MIN_PACKET + but calculate the appropriate length. + 2000-05-23 OKUJI Yoshinori * netboot/fsys_tftp.c (tftp_dir): Append "0\0" to the request diff --git a/netboot/fsys_tftp.c b/netboot/fsys_tftp.c index a26dd9091..627195f92 100644 --- a/netboot/fsys_tftp.c +++ b/netboot/fsys_tftp.c @@ -116,8 +116,12 @@ buf_fill (int abort) #endif /* Shouldn't happen. */ if (prevblock) - /* Ignore it. */ - continue; + { + /* Ignore it. */ + grub_printf ("%s:%d: warning: PREVBLOCK != 0 (0x%x)\n", + __FILE__, __LINE__, prevblock); + continue; + } len = ntohs (tr->udp.len) - sizeof (struct udphdr) - 2; if (len > TFTP_MAX_PACKET) @@ -187,8 +191,12 @@ buf_fill (int abort) /* Shouldn't happen. */ if (len > packetsize) - /* Ignore it. */ - continue; + { + /* Ignore it. */ + grub_printf ("%s:%d: warning: LEN > PACKETSIZE (0x%x > 0x%x)\n", + __FILE__, __LINE__, len, packetsize); + continue; + } block = ntohs (tp.u.ack.block = tr->u.data.block); } @@ -268,6 +276,18 @@ send_rrq (void) #ifdef TFTP_DEBUG grub_printf ("send_rrq ()\n"); + { + int i; + char *p; + + for (i = 0, p = (char *) &tp; i < len; i++) + if (p[i] >= ' ' && p[i] <= '~') + grub_putchar (p[i]); + else + grub_printf ("\\%x", (unsigned) p[i]); + + grub_putchar ('\n'); + } #endif /* Send the packet. */ return udp_transmit (arptable[ARP_SERVER].ipaddr.s_addr, ++iport, @@ -401,9 +421,9 @@ tftp_dir (char *dirname) ch = nul_terminate (dirname); /* Make the request string (octet, blksize and tsize). */ len = (grub_sprintf ((char *) tp.u.rrq, - "%s%coctet%cblksize%c%d%ctsize%c0%c0", - dirname, 0, 0, 0, TFTP_MAX_PACKET, 0, 0, 0) - + TFTP_MIN_PACKET + 1); + "%s%coctet%cblksize%c%d%ctsize%c0", + dirname, 0, 0, 0, TFTP_MAX_PACKET, 0, 0) + + sizeof (struct iphdr) + sizeof (struct udphdr) + 2 + 1); /* Restore the original DIRNAME. */ dirname[grub_strlen (dirname)] = ch; /* Save the TFTP packet so that we can reopen the file later. */