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-w32-3b33dd9b1e904fbd9522a210c5b0ebb0a941fc71.tar.gz
busybox-w32-3b33dd9b1e904fbd9522a210c5b0ebb0a941fc71.tar.bz2
busybox-w32-3b33dd9b1e904fbd9522a210c5b0ebb0a941fc71.zip
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 {
56static char verbose_flag; 56static char verbose_flag;
57static char do_continue = 0; 57static char do_continue = 0;
58 58
59/* If chunksize == 0 read till end of file */ 59static int copyfd_chunk(int fd1, int fd2, const off_t chunksize)
60static int copyfd_chunk(int fd1, int fd2, off_t chunksize)
61{ 60{
62 size_t nread; 61 size_t nread;
63 size_t nwritten; 62 size_t nwritten;
64 size_t size; 63 size_t size;
64 size_t remaining;
65 char buffer[BUFSIZ]; 65 char buffer[BUFSIZ];
66 66
67 if (chunksize) {
68 remaining = chunksize;
69 } else {
70 remaining = -1;
71 }
72
67 do { 73 do {
68 if ((chunksize > BUFSIZ) || (chunksize == 0)) { 74 if ((chunksize > BUFSIZ) || (chunksize == 0)) {
69 size = BUFSIZ; 75 size = BUFSIZ;
@@ -73,7 +79,7 @@ static int copyfd_chunk(int fd1, int fd2, off_t chunksize)
73 79
74 nread = safe_read(fd1, buffer, size); 80 nread = safe_read(fd1, buffer, size);
75 81
76 if (nread < 0) { 82 if (nread <= 0) {
77 if (chunksize) { 83 if (chunksize) {
78 perror_msg_and_die("read error"); 84 perror_msg_and_die("read error");
79 } else { 85 } else {
@@ -88,10 +94,9 @@ static int copyfd_chunk(int fd1, int fd2, off_t chunksize)
88 } 94 }
89 95
90 if (chunksize) { 96 if (chunksize) {
91 chunksize -= nwritten; 97 remaining -= nwritten;
92 } 98 }
93 99 } while (remaining != 0);
94 } while (chunksize);
95 100
96 return 0; 101 return 0;
97} 102}