From 672c0505c6c10c227c9315ed4f94746462392ea5 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 5 Jun 2011 16:46:27 +0000 Subject: Fix more FTP bugs git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3671 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/ftpc/ftpc_cmds.c | 2 +- apps/netutils/ftpc/ftpc_getfile.c | 30 +++++++++++++++++++----------- apps/netutils/ftpc/ftpc_putfile.c | 2 +- apps/netutils/ftpc/ftpc_transfer.c | 1 + 4 files changed, 22 insertions(+), 13 deletions(-) (limited to 'apps') diff --git a/apps/examples/ftpc/ftpc_cmds.c b/apps/examples/ftpc/ftpc_cmds.c index d01215753..42091760b 100755 --- a/apps/examples/ftpc/ftpc_cmds.c +++ b/apps/examples/ftpc/ftpc_cmds.c @@ -372,7 +372,7 @@ int cmd_rput(SESSION handle, int argc, char **argv) optind++; } - if (optind >= argc) + if (optind != argc) { printf("%s: Too many arguments\n "); return ERROR; diff --git a/apps/netutils/ftpc/ftpc_getfile.c b/apps/netutils/ftpc/ftpc_getfile.c index 366351636..6077b7580 100644 --- a/apps/netutils/ftpc/ftpc_getfile.c +++ b/apps/netutils/ftpc/ftpc_getfile.c @@ -181,7 +181,6 @@ static int ftpc_recvbinary(FAR struct ftpc_session_s *session, ssize_t nread; ssize_t nwritten; int err; - int ret = OK; /* Allocate an I/O buffer */ @@ -199,16 +198,20 @@ static int ftpc_recvbinary(FAR struct ftpc_session_s *session, nread = fread(buf, sizeof(char), CONFIG_FTP_BUFSIZE, rinstream); if (nread <= 0) { - /* nread == 0 means end of file */ + /* nread < 0 is an error */ if (nread < 0) { /* errno should already be set by fread */ (void)ftpc_xfrabort(session, rinstream); - ret = ERROR; + goto errout_with_buf; } - break; + + /* nread == 0 means end of file. Return success */ + + free(buf); + return OK; } /* Write the data to the file */ @@ -217,19 +220,24 @@ static int ftpc_recvbinary(FAR struct ftpc_session_s *session, if (nwritten != nread) { (void)ftpc_xfrabort(session, loutstream); - ret = ERROR; - break; + + /* If nwritten < 0 errno should already be set by fwrite. + * What would a short write mean? + */ + + goto errout_with_buf; } - session->size += nread; + /* Increment the size of the file written */ + + session->size += nwritten; } +errout_with_buf: /* Buffer allocated, errno already set */ free(buf); - return ret; + return ERROR; -errout_with_buf: - free(buf); -errout_with_err: +errout_with_err: /* Buffer not allocated, errno needs to be set */ set_errno(err); return ERROR; } diff --git a/apps/netutils/ftpc/ftpc_putfile.c b/apps/netutils/ftpc/ftpc_putfile.c index bc20853d7..4a15d7410 100644 --- a/apps/netutils/ftpc/ftpc_putfile.c +++ b/apps/netutils/ftpc/ftpc_putfile.c @@ -422,7 +422,7 @@ int ftp_putfile(SESSION handle, const char *lname, const char *rname, /* Open the local file for reading */ finstream = fopen(abslpath, "r"); - if (!finstream == 0) + if (!finstream) { ndbg("fopen() failed: %d\n", errno); goto errout_with_abspath; diff --git a/apps/netutils/ftpc/ftpc_transfer.c b/apps/netutils/ftpc/ftpc_transfer.c index f808e67fb..7bbe30f2c 100644 --- a/apps/netutils/ftpc/ftpc_transfer.c +++ b/apps/netutils/ftpc/ftpc_transfer.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3