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

sock_util: Add checks to port number parsing

Add additional checks to the port number parsing in str2ep to validate
the port number supplied in the string. This only verifies that the port
number is no longer than 5 chars and the resulting number fits in a
uint16_t.

It is still possible to supply up to 5 random chars.
parent bff86940
No related branches found
No related tags found
No related merge requests found
......@@ -171,11 +171,21 @@ int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
hostend++);
}
size_t hostlen = hostend - hoststart;
if (*(hostend + brackets_flag) == ':') {
ep_out->port = atoi(hostend + brackets_flag + 1);
char *portstart = hostend + brackets_flag + 1;
/* Checks here verify that the supplied port number is up to 5 (random)
* chars in size and result is smaller or equal to UINT16_MAX. */
if (strlen(portstart) > 5) {
return -EINVAL;
}
uint32_t port = atol(portstart);
if (port > UINT16_MAX) {
return -EINVAL;
}
ep_out->port = (uint16_t)port;
}
size_t hostlen = hostend - hoststart;
if (hostlen >= sizeof(hostbuf)) {
return -EINVAL;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment