From 585d63b30d378dcf4277eac888d8c498a084b519 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 28 May 2020 17:22:37 +0900 Subject: [PATCH] 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 ee3299ad9..28a83d416 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; }