Skip to content

Commit

Permalink
fixup! 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 12, 2019
1 parent 52f79be commit 6609ab9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion sys/include/net/sock/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *por
* @ref SOCK_URLPATH_MAXLEN bytes, if pointers are not NULL.
* Scheme part of the URL is limited to @ref SOCK_SCHEME_MAXLEN length.
*
* @param[in] url URL to split
* @pre `url != NULL`
*
* @param[in] url URL to split. Not NULL.
* @param[out] hostport where to write host:port. Can be NULL.
* @param[out] urlpath where to write url path. Can be NULL.
*
Expand Down
6 changes: 3 additions & 3 deletions sys/net/sock/sock_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ static char* _find_pathstart(const char *url)

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

char *pathstart = _find_pathstart(hoststart);

if (hostport != NULL) {
if (hostport) {
size_t hostlen = pathstart - hoststart;
/* hostlen must be smaller SOCK_HOSTPORT_MAXLEN to have space for the null
* terminator */
Expand All @@ -136,7 +136,7 @@ int sock_urlsplit(const char *url, char *hostport, char *urlpath)
hostport[hostlen] = '\0';
}

if (urlpath != NULL) {
if (urlpath) {
size_t pathlen = strlen(pathstart);
if (pathlen > SOCK_URLPATH_MAXLEN - 1) {
return -EOVERFLOW;
Expand Down

0 comments on commit 6609ab9

Please sign in to comment.