From cfdeddbd8d3db07b0fb1ffd6433d75d7a6d98f6f Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Thu, 25 Feb 2010 02:45:42 +0000 Subject: [PATCH] Fix some signed vs. unsigned 32-bit values (considering testing > 2GB file xfers). Bug-fix in zmodem_recv_file_data(), if receiving a file larger than the size specified in the ZFILE data block wouldn't work and couldn't receive a 0 byte file (would never send the ZRPOS frame). --- src/sbbs3/sexyz.c | 6 +++--- src/sbbs3/zmodem.c | 29 +++++++++++++++++++++++------ src/sbbs3/zmodem.h | 4 +++- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/sbbs3/sexyz.c b/src/sbbs3/sexyz.c index b046198120..da42a32e17 100644 --- a/src/sbbs3/sexyz.c +++ b/src/sbbs3/sexyz.c @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -1018,7 +1018,7 @@ static int receive_files(char** fname_list, int fnames) return(0); } file_bytes=ftime=total_files=total_bytes=0; - i=sscanf(block+strlen(block)+1,"%ld %lo %lo %lo %d %ld" + i=sscanf(block+strlen(block)+1,"%lu %lo %lo %lo %u %lu" ,&file_bytes /* file size (decimal) */ ,&ftime /* file time (octal unix format) */ ,&fmode /* file mode (not used) */ @@ -1055,7 +1055,7 @@ static int receive_files(char** fname_list, int fnames) } if(!file_bytes) - file_bytes=0x7fffffff; + file_bytes=0x7fffffff; /* Should we use 0xffffffff instead? */ file_bytes_left=file_bytes; if(!total_files) total_files=fnames-fnum; diff --git a/src/sbbs3/zmodem.c b/src/sbbs3/zmodem.c index 3d000ebdc4..dd99cfcf0a 100644 --- a/src/sbbs3/zmodem.c +++ b/src/sbbs3/zmodem.c @@ -1707,7 +1707,7 @@ BOOL zmodem_send_file(zmodem_t* zm, char* fname, FILE* fp, BOOL request_init, ti p += strlen(p) + 1; - sprintf(p,"%lu %lo %lo %d %u %u %d" + sprintf(p,"%lu %lo %lo %d %u %lu %d" ,zm->current_file_size ,s.st_mtime ,0UL /* file mode */ @@ -1731,11 +1731,14 @@ BOOL zmodem_send_file(zmodem_t* zm, char* fname, FILE* fp, BOOL request_init, ti lprintf(zm,LOG_DEBUG,"Sending ZFILE frame: '%s'" ,zm->tx_data_subpacket+strlen(zm->tx_data_subpacket)+1); - if(zmodem_send_bin_header(zm,zfile_frame)!=0) + if((i=zmodem_send_bin_header(zm,zfile_frame))!=0) { + lprintf(zm,LOG_DEBUG,"zmodem_send_bin_header returned %d",i); continue; - if(zmodem_send_data_subpkt(zm,ZCRCW,zm->tx_data_subpacket,p - zm->tx_data_subpacket)!=0) + } + if((i=zmodem_send_data_subpkt(zm,ZCRCW,zm->tx_data_subpacket,p - zm->tx_data_subpacket))!=0) { + lprintf(zm,LOG_DEBUG,"zmodem_send_data_subpkt returned %d",i); continue; - + } /* * wait for anything but an ZACK packet */ @@ -1785,6 +1788,8 @@ BOOL zmodem_send_file(zmodem_t* zm, char* fname, FILE* fp, BOOL request_init, ti rewind(fp); zm->errors = 0; zm->consecutive_errors = 0; + + lprintf(zm,LOG_DEBUG,"Sending %s from offset %lu", fname, pos); do { /* * and start sending @@ -2093,14 +2098,26 @@ unsigned zmodem_recv_file_data(zmodem_t* zm, FILE* fp, uint32_t offset) { int type=0; unsigned errors=0; + ulong pos; zm->transfer_start_pos=offset; zm->transfer_start_time=time(NULL); fseek(fp,offset,SEEK_SET); - while(errors<=zm->max_errors && is_connected(zm) - && (uint32_t)ftell(fp) < zm->current_file_size && !is_cancelled(zm)) { + /* zmodem.doc: + + The zmodem receiver uses the file length [from ZFILE data] as an estimate only. + It may be used to display an estimate of the transmission time, + and may be compared with the amount of free disk space. The + actual length of the received file is determined by the data + transfer. A file may grow after transmission commences, and + all the data will be sent. + */ + while(errors<=zm->max_errors && is_connected(zm) && !is_cancelled(zm)) { + + if((pos=ftell(fp)) > zm->current_file_size) + zm->current_file_size = pos; if(type!=ENDOFFRAME) zmodem_send_pos_header(zm, ZRPOS, ftell(fp), /* Hex? */ TRUE); diff --git a/src/sbbs3/zmodem.h b/src/sbbs3/zmodem.h index 2d886d04fd..fa58175ab4 100644 --- a/src/sbbs3/zmodem.h +++ b/src/sbbs3/zmodem.h @@ -11,6 +11,8 @@ #include <stdio.h> /* FILE */ +#define ZMODEM_FILE_SIZE_MAX 0xffffffff /* 32-bits, blame Chuck */ + /* * ascii constants */ @@ -234,7 +236,7 @@ typedef struct { unsigned total_files; uint32_t total_bytes; unsigned files_remaining; - unsigned bytes_remaining; + uint32_t bytes_remaining; uint32_t transfer_start_pos; time_t transfer_start_time; -- GitLab