Fix more FTP bugs

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3671 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-06-05 16:46:27 +00:00
parent 3f97ba4c55
commit 2391ac39b2
4 changed files with 22 additions and 13 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -44,6 +44,7 @@
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <poll.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>