aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2002-12-13 04:14:36 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2002-12-13 04:14:36 +0000
commit3b33dd9b1e904fbd9522a210c5b0ebb0a941fc71 (patch)
tree4888b7c3a776bf8e27c5a012d2c96e9498113eb9
parent02d7cbfe92a94d51d2c9b11bab3dc6fe2cec7e89 (diff)
downloadbusybox-3b33dd9b1e904fbd9522a210c5b0ebb0a941fc71.tar.gz
Fix possible bug if file length not known
-rw-r--r--networking/ftpgetput.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index 4cebbc71c..cad340738 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -56,14 +56,20 @@ typedef struct ftp_host_info_s {
static char verbose_flag;
static char do_continue = 0;
-/* If chunksize == 0 read till end of file */
-static int copyfd_chunk(int fd1, int fd2, off_t chunksize)
+static int copyfd_chunk(int fd1, int fd2, const off_t chunksize)
{
size_t nread;
size_t nwritten;
size_t size;
+ size_t remaining;
char buffer[BUFSIZ];
+ if (chunksize) {
+ remaining = chunksize;
+ } else {
+ remaining = -1;
+ }
+
do {
if ((chunksize > BUFSIZ) || (chunksize == 0)) {
size = BUFSIZ;
@@ -73,7 +79,7 @@ static int copyfd_chunk(int fd1, int fd2, off_t chunksize)
nread = safe_read(fd1, buffer, size);
- if (nread < 0) {
+ if (nread <= 0) {
if (chunksize) {
perror_msg_and_die("read error");
} else {
@@ -88,10 +94,9 @@ static int copyfd_chunk(int fd1, int fd2, off_t chunksize)
}
if (chunksize) {
- chunksize -= nwritten;
+ remaining -= nwritten;
}
-
- } while (chunksize);
+ } while (remaining != 0);
return 0;
}