1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-20 20:13:50 +01:00

sock_util: Limit recursion in str2ep

This commit is contained in:
Koen Zandberg 2018-07-18 15:27:31 +02:00
parent b024ff1cb8
commit 0c43dc743d
No known key found for this signature in database
GPG Key ID: 0895A893E6D2985B

View File

@ -32,9 +32,6 @@
#include "fmt.h" #include "fmt.h"
#endif #endif
#define SOCK_HOST_MAXLEN (64U) /**< maximum length of host part for
sock_udp_str2ep() */
int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *port) int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *port)
{ {
void *addr_ptr; void *addr_ptr;
@ -152,7 +149,7 @@ int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
char *hoststart = (char*)str; char *hoststart = (char*)str;
char *hostend = hoststart; char *hostend = hoststart;
char hostbuf[SOCK_HOST_MAXLEN]; char hostbuf[SOCK_HOSTPORT_MAXLEN];
memset(ep_out, 0, sizeof(sock_udp_ep_t)); memset(ep_out, 0, sizeof(sock_udp_ep_t));
@ -160,15 +157,15 @@ int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
brackets_flag = 1; brackets_flag = 1;
for (hostend = ++hoststart; *hostend && *hostend != ']'; for (hostend = ++hoststart; *hostend && *hostend != ']';
hostend++); hostend++);
if (! *hostend) { if (! *hostend || ((size_t)(hostend - hoststart) >= sizeof(hostbuf))) {
/* none found, bail out */ /* none found, bail out */
return -EINVAL; return -EINVAL;
} }
} }
else { else {
brackets_flag = 0; brackets_flag = 0;
for (hostend = hoststart; *hostend && *hostend != ':'; for (hostend = hoststart; *hostend && (*hostend != ':') && \
hostend++); ((size_t)(hostend - hoststart) < sizeof(hostbuf)); hostend++) {}
} }
size_t hostlen = hostend - hoststart; size_t hostlen = hostend - hoststart;