1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

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
This commit is contained in:
Koen Zandberg 2018-07-18 14:44:29 +02:00
parent 3096823ab4
commit b8a494fb76
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B

View File

@ -126,7 +126,13 @@ int sock_urlsplit(const char *url, char *hostport, char *urlpath)
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);
if (pathlen) {