summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorGlenn L McGrath2002-12-18 02:47:40 +0000
committerGlenn L McGrath2002-12-18 02:47:40 +0000
commit1643f419868dc245f88f35a1fda8b7ac8b66b6b6 (patch)
treec6f54d05058b0e263bca96c007dc463941149c73 /networking
parent688cf014af12c33e2b1dc95834e31db3d3014899 (diff)
downloadbusybox-1643f419868dc245f88f35a1fda8b7ac8b66b6b6.zip
busybox-1643f419868dc245f88f35a1fda8b7ac8b66b6b6.tar.gz
When retrieving a file dont open file until we have to to prevent files of size 0 being created when retrieval fails, bug found by Jeff Angielski
Diffstat (limited to 'networking')
-rw-r--r--networking/ftpgetput.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index a23c64a..44e91c3 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -174,16 +174,9 @@ static int ftp_recieve(FILE *control_stream, const char *host, const char *local
filesize = atol(buf + 4);
}
- /* only make a local file if we know that one exists on the remote server */
- if (do_continue) {
- fd_local = xopen(local_file, O_APPEND | O_WRONLY);
- } else {
- fd_local = xopen(local_file, O_CREAT | O_TRUNC | O_WRONLY);
- }
-
if (do_continue) {
struct stat sbuf;
- if (fstat(fd_local, &sbuf) < 0) {
+ if (lstat(local_file, &sbuf) < 0) {
perror_msg_and_die("fstat()");
}
if (sbuf.st_size > 0) {
@@ -206,6 +199,13 @@ static int ftp_recieve(FILE *control_stream, const char *host, const char *local
error_msg_and_die("RETR error: %s", buf + 4);
}
+ /* only make a local file if we know that one exists on the remote server */
+ if (do_continue) {
+ fd_local = xopen(local_file, O_APPEND | O_WRONLY);
+ } else {
+ fd_local = xopen(local_file, O_CREAT | O_TRUNC | O_WRONLY);
+ }
+
/* Copy the file */
if (copyfd(fd_data, fd_local, filesize) == -1) {
exit(EXIT_FAILURE);