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';
Hi sebastian, Thanks for hacking my gsoc code so quickly! On Sat, Aug 8, 2009 at 9:29 PM, Sebastian Herbszt <herbszt at gmx.de> wrote:> - 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 */ > + >Yeah, this make the things much easier, but should we make sure the options are converted to low-case? Because the strings in the tftp_options are all in low-case, and I'm not sure the options are all transfromed in the low-case. And last, thanks for your patch! -- regards liu Aleaxander
So, here is the new patch:>From f7e36b4de4387f8662dbb88b550915a021e8f99b Mon Sep 17 00:00:00 2001From: Liu Aleaxander <Aleaxander at gmail.com> Date: Sat, 8 Aug 2009 16:05:08 +0800 Subject: [PATCH] core:PXELINUX: fix the OACK option parsing bug. the current code can just handle one option beacuse I put the do-while loop in the wrong position. Signed-off-by: Liu Aleaxander <Aleaxander at gmail.com> --- core/pxe.c | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/pxe.c b/core/pxe.c index 81d3e23..bda1a54 100644 --- a/core/pxe.c +++ b/core/pxe.c @@ -928,20 +928,20 @@ 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 */ - } - - /* - * Parse option pointed to by options; guaranteed to be null-terminated - */ - p = options; do { + dst = src = options; + while (buffersize--) { + if (*src == 0) + break; /* found a final null */ + *dst++ = *src++ | 0x20; + if (!buffersize) + goto done; /* found no final null */ + } + + /* + * Parse option pointed to by options; guaranteed to be null-terminated + */ + p = options; tftp_opt = tftp_options; for (i = 0; i < tftp_opts; i++) { if (!strncmp(p, tftp_opt->str_ptr,tftp_opt->str_len)) -- 1.5.6.rc0 -- regards liu Aleaxander
Seemingly Similar Threads
- [PATCH] core:PXELINUX: fix the OACK option parsing bug.
- [PATCH] core: Bad read of file size over TFTP
- tftp upload and OACK problem.
- 2.2.27 panic file mail-index-map.c: line 549 (mail_index_map_lookup_seq_range): assertion failed: (first_uid > 0)
- Allwell doesn't respond to OACK with ACK in TFTP