Update.
* resolv/inet_net_pton.c (inet_net_pton_ipv4): Prevent buffer overruns.
This commit is contained in:
parent
81ca53df7d
commit
0c03cb9bed
@ -1,5 +1,8 @@
|
|||||||
1999-10-02 Ulrich Drepper <drepper@cygnus.com>
|
1999-10-02 Ulrich Drepper <drepper@cygnus.com>
|
||||||
|
|
||||||
|
* resolv/inet_net_pton.c (inet_net_pton_ipv4): Prevent buffer
|
||||||
|
overruns.
|
||||||
|
|
||||||
* resolv/tst-aton.c (main): Add more tests.
|
* resolv/tst-aton.c (main): Add more tests.
|
||||||
|
|
||||||
* resolv/inet_addr.c (inet_aton): Correct some problems with to
|
* resolv/inet_addr.c (inet_aton): Correct some problems with to
|
||||||
|
@ -102,35 +102,41 @@ inet_net_pton_ipv4(src, dst, size)
|
|||||||
if (size <= 0)
|
if (size <= 0)
|
||||||
goto emsgsize;
|
goto emsgsize;
|
||||||
*dst = 0, dirty = 0;
|
*dst = 0, dirty = 0;
|
||||||
|
tmp = 0; /* To calm down gcc. */
|
||||||
src++; /* skip x or X. */
|
src++; /* skip x or X. */
|
||||||
while ((ch = *src++) != '\0' &&
|
while (isxdigit((ch = *src++))) {
|
||||||
isascii(ch) && isxdigit(ch)) {
|
|
||||||
ch = _tolower(ch);
|
ch = _tolower(ch);
|
||||||
n = strchr(xdigits, ch) - xdigits;
|
n = (const char *) __rawmemchr(xdigits, ch) - xdigits;
|
||||||
assert(n >= 0 && n <= 15);
|
assert(n >= 0 && n <= 15);
|
||||||
*dst |= n;
|
if (dirty == 0)
|
||||||
if (!dirty++)
|
tmp = n << 4;
|
||||||
*dst <<= 4;
|
|
||||||
else if (size-- > 0)
|
|
||||||
*++dst = 0, dirty = 0;
|
|
||||||
else
|
else
|
||||||
|
tmp |= n;
|
||||||
|
if (++dirty == 2) {
|
||||||
|
if (size-- <= 0)
|
||||||
goto emsgsize;
|
goto emsgsize;
|
||||||
|
*dst++ = (u_char) tmp;
|
||||||
|
dirty = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dirty) {
|
||||||
|
if (size-- <= 0)
|
||||||
|
goto emsgsize;
|
||||||
|
*dst = (u_char) tmp;
|
||||||
}
|
}
|
||||||
if (dirty)
|
|
||||||
size--;
|
|
||||||
} else if (isascii(ch) && isdigit(ch)) {
|
} else if (isascii(ch) && isdigit(ch)) {
|
||||||
/* Decimal: eat dotted digit string. */
|
/* Decimal: eat dotted digit string. */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
do {
|
do {
|
||||||
n = strchr(xdigits, ch) - xdigits;
|
n = ((const char *) __rawmemchr(xdigits, ch)
|
||||||
|
- xdigits);
|
||||||
assert(n >= 0 && n <= 9);
|
assert(n >= 0 && n <= 9);
|
||||||
tmp *= 10;
|
tmp *= 10;
|
||||||
tmp += n;
|
tmp += n;
|
||||||
if (tmp > 255)
|
if (tmp > 255)
|
||||||
goto enoent;
|
goto enoent;
|
||||||
} while ((ch = *src++) != '\0' &&
|
} while (isascii((ch = *src++)) && isdigit(ch));
|
||||||
isascii(ch) && isdigit(ch));
|
|
||||||
if (size-- <= 0)
|
if (size-- <= 0)
|
||||||
goto emsgsize;
|
goto emsgsize;
|
||||||
*dst++ = (u_char) tmp;
|
*dst++ = (u_char) tmp;
|
||||||
@ -151,12 +157,11 @@ inet_net_pton_ipv4(src, dst, size)
|
|||||||
ch = *src++; /* Skip over the /. */
|
ch = *src++; /* Skip over the /. */
|
||||||
bits = 0;
|
bits = 0;
|
||||||
do {
|
do {
|
||||||
n = strchr(xdigits, ch) - xdigits;
|
n = (const char *) __rawmemchr(xdigits, ch) - xdigits;
|
||||||
assert(n >= 0 && n <= 9);
|
assert(n >= 0 && n <= 9);
|
||||||
bits *= 10;
|
bits *= 10;
|
||||||
bits += n;
|
bits += n;
|
||||||
} while ((ch = *src++) != '\0' &&
|
} while (isascii((ch = *src++)) && isdigit(ch));
|
||||||
isascii(ch) && isdigit(ch));
|
|
||||||
if (ch != '\0')
|
if (ch != '\0')
|
||||||
goto enoent;
|
goto enoent;
|
||||||
if (bits > 32)
|
if (bits > 32)
|
||||||
|
Loading…
Reference in New Issue
Block a user