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/05/28 12:04:38 UTC
[incubator-nuttx-apps] 01/02: netlib_parseurl: Fix pathlen check
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 585d63b30d378dcf4277eac888d8c498a084b519
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Thu May 28 17:22:37 2020 +0900
netlib_parseurl: Fix pathlen check
---
netutils/netlib/netlib_parseurl.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/netutils/netlib/netlib_parseurl.c b/netutils/netlib/netlib_parseurl.c
index ee3299a..28a83d4 100644
--- a/netutils/netlib/netlib_parseurl.c
+++ b/netutils/netlib/netlib_parseurl.c
@@ -76,6 +76,7 @@ int netlib_parseurl(FAR const char *str, FAR struct url_s *url)
FAR char *dest;
int bytesleft;
int ret = OK;
+ size_t pathlen;
/* extract the protocol field, a set of a-z letters */
@@ -193,7 +194,17 @@ int netlib_parseurl(FAR const char *str, FAR struct url_s *url)
/* The copy the rest of the file name to the user buffer */
- strncpy(dest, src, bytesleft);
- url->path[bytesleft - 1] = '\0';
+ pathlen = strlen(src);
+ if (bytesleft >= pathlen + 1)
+ {
+ memcpy(dest, src, pathlen);
+ dest[pathlen] = '\0';
+ }
+ else
+ {
+ dest[0] = '\0';
+ ret = -E2BIG;
+ }
+
return ret;
}