]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - net/tftp.c
Fix TFTP OACK code for short packets.
[people/ms/u-boot.git] / net / tftp.c
index fb2f50564e9d0bda8760c3cb6cfd047d54c65c76..5ee7676466925cafcdde9a8eee38f7a4b13282f5 100644 (file)
@@ -276,8 +276,12 @@ TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
 #endif
                TftpState = STATE_OACK;
                TftpServerPort = src;
-               /* Check for 'blksize' option */
-               for (i=0;i<len-8;i++) {
+               /*
+                * Check for 'blksize' option.
+                * Careful: "i" is signed, "len" is unsigned, thus
+                * something like "len-8" may give a *huge* number
+                */
+               for (i=0; i+8<len; i++) {
                        if (strcmp ((char*)pkt+i,"blksize") == 0) {
                                TftpBlkSize = (unsigned short)
                                        simple_strtoul((char*)pkt+i+8,NULL,10);