netlib_parseurl: Fix pathlen check

This commit is contained in:
YAMAMOTO Takashi 2020-05-28 17:22:37 +09:00 committed by Xiang Xiao
parent a455f13ec1
commit 585d63b30d

View File

@ -76,6 +76,7 @@ int netlib_parseurl(FAR const char *str, FAR struct url_s *url)
FAR char *dest; FAR char *dest;
int bytesleft; int bytesleft;
int ret = OK; int ret = OK;
size_t pathlen;
/* extract the protocol field, a set of a-z letters */ /* 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 */ /* The copy the rest of the file name to the user buffer */
strncpy(dest, src, bytesleft); pathlen = strlen(src);
url->path[bytesleft - 1] = '\0'; if (bytesleft >= pathlen + 1)
{
memcpy(dest, src, pathlen);
dest[pathlen] = '\0';
}
else
{
dest[0] = '\0';
ret = -E2BIG;
}
return ret; return ret;
} }