Fix parsing of 6to4 addresses

The last two bytes of the IPv4 address in 6to4 addresses were not
parsed correctly since version 5.0.19. (Fixes #699928.)
This commit is contained in:
Marco d'Itri 2013-03-31 05:18:37 +02:00
parent 3dacfba4f0
commit 9b1706c1e1

17
whois.c
View File

@ -1058,17 +1058,22 @@ char *convert_6to4(const char *s)
new = malloc(sizeof("255.255.255.255"));
sprintf(new, "%d.%d.%d.%d", *(ip + 2), *(ip + 3), *(ip + 4), *(ip + 5));
#else
int items;
unsigned int a, b;
char c;
if (sscanf(s, "2002:%x::", &a) == 1) {
new = malloc(sizeof("255.255.255.255"));
sprintf(new, "%d.%d.0.0", a >> 8, a & 0xff);
return new;
}
items = sscanf(s, "2002:%x:%x%c", &a, &b, &c);
if (sscanf(s, "2002:%x:%x:", &a, &b) != 2)
if (items <= 0 || items == 2 || (items == 3 && c != ':'))
return strdup("0.0.0.0");
if (items == 1) {
items = sscanf(s, "2002:%x:%c", &a, &c);
if (items != 2 || c != ':')
return strdup("0.0.0.0");
b = 0;
}
new = malloc(sizeof("255.255.255.255"));
sprintf(new, "%d.%d.%d.%d", a >> 8, a & 0xff, b >> 8, b & 0xff);
#endif