Skip to content
Snippets Groups Projects
Unverified Commit b8a494fb authored by Koen Zandberg's avatar Koen Zandberg
Browse files

sock_util: Prevent overflow in sock_urlsplit

This adds a length check to verify if the host-port part of the URL fits
in the supplied buffer
parent 3096823a
No related branches found
No related tags found
No related merge requests found
...@@ -126,7 +126,13 @@ int sock_urlsplit(const char *url, char *hostport, char *urlpath) ...@@ -126,7 +126,13 @@ int sock_urlsplit(const char *url, char *hostport, char *urlpath)
char *pathstart = _find_pathstart(hoststart); char *pathstart = _find_pathstart(hoststart);
memcpy(hostport, hoststart, pathstart - hoststart); 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);
size_t pathlen = strlen(pathstart); size_t pathlen = strlen(pathstart);
if (pathlen) { if (pathlen) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment