X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Ffile_ops.c;h=413e32da1aa6f62f6fc41fc6f0d4b3916c6f0466;hb=4a30bae41553c9c6331aebe7c7b7f72b787f7860;hp=ada35251401c8489c25c0e5e8fef1af54fc73217;hpb=5a287bfe887045edc721294b24c1e433880c033d;p=citadel.git diff --git a/citadel/file_ops.c b/citadel/file_ops.c index ada352514..413e32da1 100644 --- a/citadel/file_ops.c +++ b/citadel/file_ops.c @@ -639,9 +639,9 @@ void cmd_read(char *cmdbuf) { long start_pos; size_t bytes; - size_t actual_bytes; - char *buf = NULL; + char buf[SIZ]; + /* The client will transmit its requested offset and byte count */ start_pos = extract_long(cmdbuf, 0); bytes = extract_int(cmdbuf, 1); @@ -651,24 +651,24 @@ void cmd_read(char *cmdbuf) return; } - if (bytes > 100000) bytes = 100000; - buf = malloc(bytes + 1); + /* If necessary, reduce the byte count to the size of our buffer */ + if (bytes > sizeof(buf)) { + bytes = sizeof(buf); + } fseek(CC->download_fp, start_pos, 0); - - actual_bytes = fread(buf, 1, bytes, CC->download_fp); - if (actual_bytes > 0) { - cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes); + bytes = fread(buf, 1, bytes, CC->download_fp); + if (bytes > 0) { + /* Tell the client the actual byte count and transmit it */ + cprintf("%d %d\n", BINARY_FOLLOWS, (int)bytes); client_write(buf, bytes); } else { cprintf("%d %s\n", ERROR, strerror(errno)); } - free(buf); } - /* * write to the upload file */