You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/12/13 17:14:54 UTC
[incubator-nuttx-apps] 03/04: netutils/ftpc: add some error checks
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 810398de016beb9c790515d7ff6818b1803d951a
Author: Juha Niskanen <ju...@haltian.com>
AuthorDate: Sun Dec 13 17:35:13 2020 +0200
netutils/ftpc: add some error checks
Signed-off-by: Juha Niskanen <ju...@haltian.com>
---
netutils/ftpc/ftpc_login.c | 5 ++++-
netutils/ftpc/ftpc_mkdir.c | 5 +++++
netutils/ftpc/ftpc_rename.c | 12 +++++++++++-
netutils/ftpc/ftpc_rmdir.c | 5 +++++
netutils/ftpc/ftpc_transfer.c | 6 +++++-
5 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/netutils/ftpc/ftpc_login.c b/netutils/ftpc/ftpc_login.c
index 8f21309..6f9f534 100644
--- a/netutils/ftpc/ftpc_login.c
+++ b/netutils/ftpc/ftpc_login.c
@@ -187,7 +187,10 @@ int ftpc_relogin(FAR struct ftpc_session_s *session)
FTPC_SET_LOGGEDIN(session);
session->homerdir = ftpc_rpwd((SESSION)session);
- session->currdir = strdup(session->homerdir);
+ if (session->homerdir != NULL)
+ {
+ session->currdir = strdup(session->homerdir);
+ }
/* If the user has requested a special start up directory, then change to
* that directory now.
diff --git a/netutils/ftpc/ftpc_mkdir.c b/netutils/ftpc/ftpc_mkdir.c
index 27981b4..bd32121 100644
--- a/netutils/ftpc/ftpc_mkdir.c
+++ b/netutils/ftpc/ftpc_mkdir.c
@@ -85,6 +85,11 @@ int ftpc_mkdir(SESSION handle, FAR const char *path)
int ret;
ptr = strdup(path);
+ if (!ptr)
+ {
+ return ERROR;
+ }
+
ftpc_stripslash(ptr);
/* Send the MKD request. The MKD request asks the server to create a new
diff --git a/netutils/ftpc/ftpc_rename.c b/netutils/ftpc/ftpc_rename.c
index ec8aae8..c5d735a 100644
--- a/netutils/ftpc/ftpc_rename.c
+++ b/netutils/ftpc/ftpc_rename.c
@@ -86,6 +86,11 @@ int ftpc_rename(SESSION handle, FAR const char *oldname, FAR const char *newname
int ret;
oldcopy = strdup(oldname);
+ if (!oldcopy)
+ {
+ return ERROR;
+ }
+
ftpc_stripslash(oldcopy);
/* A RNFR request asks the server to begin renaming a file. A typical
@@ -107,7 +112,13 @@ int ftpc_rename(SESSION handle, FAR const char *oldname, FAR const char *newname
return ERROR;
}
+ free(oldcopy);
newcopy = strdup(newname);
+ if (!newcopy)
+ {
+ return ERROR;
+ }
+
ftpc_stripslash(newcopy);
/* A RNTO request asks the server to finish renaming a file. RNTO must
@@ -128,7 +139,6 @@ int ftpc_rename(SESSION handle, FAR const char *oldname, FAR const char *newname
ret = ftpc_cmd(session, "RNTO %s", newcopy);
- free(oldcopy);
free(newcopy);
return ret;
}
diff --git a/netutils/ftpc/ftpc_rmdir.c b/netutils/ftpc/ftpc_rmdir.c
index 4cf5cdf..5f78ef2 100644
--- a/netutils/ftpc/ftpc_rmdir.c
+++ b/netutils/ftpc/ftpc_rmdir.c
@@ -83,6 +83,11 @@ int ftpc_rmdir(SESSION handle, FAR const char *path)
int ret;
ptr = strdup(path);
+ if (!ptr)
+ {
+ return ERROR;
+ }
+
ftpc_stripslash(ptr);
/* An RMD request asks the server to remove a directory. A typical server
diff --git a/netutils/ftpc/ftpc_transfer.c b/netutils/ftpc/ftpc_transfer.c
index 72cbace..b983a13 100644
--- a/netutils/ftpc/ftpc_transfer.c
+++ b/netutils/ftpc/ftpc_transfer.c
@@ -557,7 +557,11 @@ int ftpc_xfrmode(struct ftpc_session_s *session, uint8_t xfrmode)
ret = ftpc_cmd(session, "TYPE %c",
xfrmode == FTPC_XFRMODE_ASCII ? 'A' : 'I');
- UNUSED(ret);
+ if (ret < 0)
+ {
+ return ERROR;
+ }
+
session->xfrmode = xfrmode;
}