Skip to content

Commit

Permalink
fixup! sys/net/sock_util: Accept null pointers in urlsplit
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrolanzieri committed Jun 11, 2019
1 parent 8bda1dd commit 52f79be
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions sys/net/sock/sock_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,34 +117,32 @@ static char* _find_pathstart(const char *url)

int sock_urlsplit(const char *url, char *hostport, char *urlpath)
{
assert(url);
assert(url != NULL);
char *hoststart = _find_hoststart(url);
if (!hoststart) {
return -EINVAL;
}

char *pathstart = _find_pathstart(hoststart);

if (hostport) {
if (hostport != NULL) {
size_t hostlen = pathstart - hoststart;
/* hostlen must be smaller SOCK_HOSTPORT_MAXLEN to have space for the null
* terminator */
if (hostlen > SOCK_HOSTPORT_MAXLEN - 1) {
return -EOVERFLOW;
}
memcpy(hostport, hoststart, hostlen);
*(hostport + hostlen) = '\0';
hostport[hostlen] = '\0';
}

if (urlpath) {
if (urlpath != NULL) {
size_t pathlen = strlen(pathstart);
if (pathlen) {
if (pathlen > SOCK_URLPATH_MAXLEN - 1) {
return -EOVERFLOW;
}
memcpy(urlpath, pathstart, pathlen);
if (pathlen > SOCK_URLPATH_MAXLEN - 1) {
return -EOVERFLOW;
}
*(urlpath + pathlen) = '\0';
memcpy(urlpath, pathstart, pathlen);
urlpath[pathlen] = '\0';
}
return 0;
}
Expand Down

0 comments on commit 52f79be

Please sign in to comment.