From c9d47b61ce06029a23eb73598fc0002e5beb6155 Mon Sep 17 00:00:00 2001 From: Michael Hampton Date: Sun, 29 Sep 2002 04:41:43 +0000 Subject: [PATCH] * file_ops.c: cmd_read() now returns a short read at end-of-file instead of 4096, this prevents trailing garbage on the downloaded file; also it now succeeds if the requested number of bytes is > 4096; it simply returns only 4096 bytes. --- citadel/ChangeLog | 7 ++++++- citadel/file_ops.c | 15 ++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index ba660c009..34a94238c 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,10 @@ $Log$ + Revision 601.10 2002/09/29 04:41:43 error + * file_ops.c: cmd_read() now returns a short read at end-of-file instead of + 4096, this prevents trailing garbage on the downloaded file; also it now + succeeds if the requested number of bytes is > 4096; it simply returns + only 4096 bytes. + Revision 601.9 2002/09/27 06:53:20 error * Allow multiple simultaneous IPC connections. All changes necessary for the client to use the new code are necessarily included. @@ -4016,4 +4022,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/file_ops.c b/citadel/file_ops.c index ca089bac1..a6ce2f82a 100644 --- a/citadel/file_ops.c +++ b/citadel/file_ops.c @@ -680,7 +680,8 @@ void cmd_ucls(char *cmd) void cmd_read(char *cmdbuf) { long start_pos; - int bytes; + size_t bytes; + size_t actual_bytes; char buf[4096]; start_pos = extract_long(cmdbuf, 0); @@ -692,16 +693,12 @@ void cmd_read(char *cmdbuf) return; } - if (bytes > 4096) { - cprintf("%d You may not read more than 4096 bytes.\n", - ERROR); - return; - } + if (bytes > 4096) bytes = 4096; fseek(CC->download_fp, start_pos, 0); - fread(buf, bytes, 1, CC->download_fp); - cprintf("%d %d\n", BINARY_FOLLOWS, bytes); - client_write(buf, bytes); + actual_bytes = fread(buf, 1, bytes, CC->download_fp); + cprintf("%d %d\n", BINARY_FOLLOWS, actual_bytes); + client_write(buf, actual_bytes); } -- 2.30.2