mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-04-10 14:23:42 +02:00
Disallow leading zeroes when parsing IPv4 addresses
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
This commit is contained in:
@@ -2667,7 +2667,6 @@ static int x509_inet_pton_ipv6(const char *src, void *dst)
|
||||
|
||||
static int x509_inet_pton_ipv4(const char *src, void *dst)
|
||||
{
|
||||
/* note: allows leading 0's, e.g. 000.000.000.000 */
|
||||
const unsigned char *p = (const unsigned char *) src;
|
||||
uint8_t *res = (uint8_t *) dst;
|
||||
uint8_t digit, num_digits = 0;
|
||||
@@ -2681,6 +2680,13 @@ static int x509_inet_pton_ipv4(const char *src, void *dst)
|
||||
if (digit > 9) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Don't allow leading zeroes. These might mean octal format,
|
||||
* which this implementation does not support. */
|
||||
if (octet == 0 && num_digits > 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
octet = octet * 10 + digit;
|
||||
num_digits++;
|
||||
p++;
|
||||
|
||||
Reference in New Issue
Block a user