fix(lwip): fix aton prase wrong parameters

This commit is contained in:
dongheng
2019-07-02 15:40:46 +08:00
parent 735111069b
commit d52138f4d6
2 changed files with 30 additions and 0 deletions

View File

@ -160,6 +160,12 @@ ip4addr_aton(const char *cp, ip4_addr_t *addr)
u32_t parts[4];
u32_t *pp = parts;
#if ESP_IP4_ATON
char ch;
unsigned long cutoff;
int cutlim;
#endif
c = *cp;
for (;;) {
/*
@ -181,6 +187,27 @@ ip4addr_aton(const char *cp, ip4_addr_t *addr)
base = 8;
}
}
#if ESP_IP4_ATON
cutoff =(unsigned long)0xffffffff / (unsigned long)base;
cutlim =(unsigned long)0xffffffff % (unsigned long)base;
for (;;) {
if (isdigit(c)) {
ch = (int)(c - '0');
if (val > cutoff || (val == cutoff && ch > cutlim))
return (0);
val = (val * base) + (int)(c - '0');
c = *++cp;
} else if (base == 16 && isxdigit(c)) {
ch = (int)(c + 10 - (islower(c) ? 'a' : 'A'));
if (val > cutoff || (val == cutoff && ch > cutlim))
return (0);
val = (val << 4) | (int)(c + 10 - (islower(c) ? 'a' : 'A'));
c = *++cp;
} else
break;
}
#else
for (;;) {
if (isdigit(c)) {
val = (val * base) + (u32_t)(c - '0');
@ -192,6 +219,8 @@ ip4addr_aton(const char *cp, ip4_addr_t *addr)
break;
}
}
#endif
if (c == '.') {
/*
* Internet format:

View File

@ -53,6 +53,7 @@
#include "driver/soc.h"
#define ESP_LWIP 1
#define ESP_IP4_ATON 1
#ifdef CONFIG_ESP_DNS
#define ESP_DNS 1