Skip to content

Commit

Permalink
[tftp] Allow fetching larger files by wrapping block number
Browse files Browse the repository at this point in the history
This patch adds TFTP support for files larger than 65535 blocks by
wrapping the 16-bit block number.

Reported-by: Mark Johnson <johnson.nh@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Signed-off-by: Marty Connor <mdc@etherboot.org>
  • Loading branch information
stefanha authored and Marty Connor committed Jan 15, 2010
1 parent 734061e commit dd99ee9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/net/udp/tftp.c
Expand Up @@ -747,7 +747,7 @@ static int tftp_rx_data ( struct tftp_request *tftp,
struct io_buffer *iobuf ) {
struct tftp_data *data = iobuf->data;
struct xfer_metadata meta;
int block;
unsigned int block;
off_t offset;
size_t data_len;
int rc;
Expand All @@ -759,14 +759,17 @@ static int tftp_rx_data ( struct tftp_request *tftp,
rc = -EINVAL;
goto done;
}
if ( data->block == 0 ) {

/* Calculate block number */
block = ( ( bitmap_first_gap ( &tftp->bitmap ) + 1 ) & ~0xffff );
if ( data->block == 0 && block == 0 ) {
DBGC ( tftp, "TFTP %p received data block 0\n", tftp );
rc = -EINVAL;
goto done;
}
block += ( ntohs ( data->block ) - 1 );

/* Extract data */
block = ( ntohs ( data->block ) - 1 );
offset = ( block * tftp->blksize );
iob_pull ( iobuf, sizeof ( *data ) );
data_len = iob_len ( iobuf );
Expand Down

0 comments on commit dd99ee9

Please sign in to comment.