mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 22:58:50 +01:00
Minor tor_inet_pton bug fixes
In particular: * Disallow "0x10::" * Don't blow up on ":" * Disallow "::10000"
This commit is contained in:
parent
53dac6df18
commit
edc561432a
1 changed files with 14 additions and 8 deletions
|
@ -1733,14 +1733,19 @@ tor_inet_pton(int af, const char *src, void *dst)
|
||||||
return 0;
|
return 0;
|
||||||
if (TOR_ISXDIGIT(*src)) {
|
if (TOR_ISXDIGIT(*src)) {
|
||||||
char *next;
|
char *next;
|
||||||
|
int len;
|
||||||
long r = strtol(src, &next, 16);
|
long r = strtol(src, &next, 16);
|
||||||
if (next > 4+src)
|
tor_assert(next != NULL);
|
||||||
return 0;
|
tor_assert(next != src);
|
||||||
if (next == src)
|
|
||||||
return 0;
|
|
||||||
if (r<0 || r>65536)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
len = *next == '\0' ? eow - src : next - src;
|
||||||
|
if (len > 4)
|
||||||
|
return 0;
|
||||||
|
if (len > 1 && !TOR_ISXDIGIT(src[1]))
|
||||||
|
return 0; /* 0x is not valid */
|
||||||
|
|
||||||
|
tor_assert(r >= 0);
|
||||||
|
tor_assert(r < 65536);
|
||||||
words[i++] = (uint16_t)r;
|
words[i++] = (uint16_t)r;
|
||||||
setWords++;
|
setWords++;
|
||||||
src = next;
|
src = next;
|
||||||
|
@ -1750,7 +1755,8 @@ tor_inet_pton(int af, const char *src, void *dst)
|
||||||
} else if (*src == ':' && i > 0 && gapPos == -1) {
|
} else if (*src == ':' && i > 0 && gapPos == -1) {
|
||||||
gapPos = i;
|
gapPos = i;
|
||||||
++src;
|
++src;
|
||||||
} else if (*src == ':' && i == 0 && src[1] == ':' && gapPos==-1) {
|
} else if (*src == ':' && i == 0 && src+1 < eow && src[1] == ':' &&
|
||||||
|
gapPos == -1) {
|
||||||
gapPos = i;
|
gapPos = i;
|
||||||
src += 2;
|
src += 2;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue