net: tftp: Fix load_block offset calculation
authorLey Foon Tan <ley.foon.tan@intel.com>
Tue, 25 Aug 2020 02:26:37 +0000 (10:26 +0800)
committerTom Rini <trini@konsulko.com>
Wed, 30 Sep 2020 20:48:18 +0000 (16:48 -0400)
When load the last block, the "len" might not be a block size. This cause
loading the incorrect last block data.

The fix change "len" to tftp_block_size and minus one tftp_block_size
for offset calculation.

Use same offset calculation formula as in store_block().

Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com>
Reviewed-By: Ramon Fried <rfried.dev@gmail.com>
net/tftp.c

index 1c00387..6fdb1a8 100644 (file)
@@ -234,7 +234,8 @@ static void new_transfer(void)
 static int load_block(unsigned block, uchar *dst, unsigned len)
 {
        /* We may want to get the final block from the previous set */
-       ulong offset = ((int)block - 1) * len + tftp_block_wrap_offset;
+       ulong offset = block * tftp_block_size + tftp_block_wrap_offset -
+                      tftp_block_size;
        ulong tosend = len;
 
        tosend = min(net_boot_file_size - offset, tosend);