[syslinux] [PATCH] pxe: fix OACK packet handling

Sebastian Herbszt herbszt at gmx.de
Sat Aug 8 06:29:54 PDT 2009


The current code only works iff the tsize option is set.
This patch fixes the handling of the OACK packet and makes the code
work with all combinations of the tsize and blksize options.

Signed-off-by: Sebastian Herbszt <herbszt at gmx.de>

diff --git a/core/pxe.c b/core/pxe.c
index 81d3e23..a4b8a14 100644
--- a/core/pxe.c
+++ b/core/pxe.c
@@ -913,8 +913,10 @@ static void pxe_searchdir(char *filename, struct file *file)
          * Now we need to parse the OACK packet to get the transfer
          * and packet sizes.
          */
-        if (!buffersize)
+        if (!buffersize) {
+            filesize = -1;
             goto done;       /* No options acked */
+        }
         
         /*
          * If we find an option which starts with a NUL byte,
@@ -928,15 +930,9 @@ static void pxe_searchdir(char *filename, struct file *file)
         if (*options == 0)
             goto done;
 
-        dst = src = options;
-        while (buffersize--) {
-            if (*src == 0)
-                break;          /* found a final null */
-            *dst++ = *src++ | 0x20;
-            if (!buffersize)
-                goto done;  /* found no final null */
-        }
-        
+        if (*(options + buffersize - 1) != 0)
+            goto done;  /* found no final null */
+
         /* 
          * Parse option pointed to by options; guaranteed to be null-terminated
          */
@@ -944,8 +940,10 @@ static void pxe_searchdir(char *filename, struct file *file)
         do {
             tftp_opt = tftp_options;
             for (i = 0; i < tftp_opts; i++) {
-                if (!strncmp(p, tftp_opt->str_ptr,tftp_opt->str_len))
+                if (!strncmp(p, tftp_opt->str_ptr,tftp_opt->str_len)) {
+                    buffersize -= tftp_opt->str_len;
                     break;
+                }
                 tftp_opt++;
             }
             if (i == tftp_opts)
@@ -954,13 +952,15 @@ static void pxe_searchdir(char *filename, struct file *file)
             p += tftp_opt->str_len;
             
             /* get the address of the filed that we want to write on */
-            data_ptr = (uint32_t *)((char *)file + tftp_opt->offset);
+            data_ptr = (uint32_t *)((char *)open_file + tftp_opt->offset);
             *data_ptr = 0;
             
             /* do convert a number-string to decimal number, just like atoi */
             while (buffersize--) {
-                if (*p == 0)
+                if (*p == 0) {
+                    p++;
                     break;              /* found a final null */
+                }
                 if (*p > '9')
                     goto err_reply;     /* Not a decimal digit */
                 *data_ptr = *data_ptr * 10 + *p++ - '0';




More information about the Syslinux mailing list