Commit e3019c82 authored by roel0's avatar roel0

#453 accepts bytes greater than 255

parent ee3a0e98
......@@ -114,6 +114,7 @@ int pico_string_to_ipv4(const char *ipstr, uint32_t *ip)
};
int cnt = 0;
char p;
uint16_t overflow = 0;
if (pico_string_check_null_args(ipstr, ip) < 0)
return -1;
......@@ -121,7 +122,11 @@ int pico_string_to_ipv4(const char *ipstr, uint32_t *ip)
while((p = *ipstr++) != 0 && cnt < PICO_SIZE_IP4)
{
if (pico_is_digit(p)) {
buf[cnt] = (uint8_t)((10 * buf[cnt]) + (p - '0'));
overflow = (uint16_t) ((10 * buf[cnt]) + (p - '0'));
if(overflow > UINT8_MAX) {
return -1;
}
buf[cnt] = (uint8_t) overflow;
} else if (p == '.') {
cnt++;
} else {
......
......@@ -56,6 +56,7 @@ START_TEST (test_ipv4)
memset(ipstr, 0, 12);
pico_ipv4_to_string(ipstr, ipaddr.addr);
fail_if(strncmp(ipstr, "192.168.1.1", 11) != 0, "Error ipv4 to string");
fail_if(pico_string_to_ipv4("300.300.300.300", &(ipaddr.addr)) != -1, "Error string to ipv4");
/*valid_netmask*/
fail_if(pico_ipv4_valid_netmask(long_be(nm32.addr)) != 32, "Error checking netmask");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment