X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fregression%2Finet_pton-empty-last-field.c;h=b06fa113d6aeb9273bf765e2f83dd379a087ed9b;hb=2c671f66e28ac079ae1148f5135c9a52129cc807;hp=eef44dce364f565282ead6c2dcd536ddcf426c62;hpb=d031c05caf661a1ebfff8050ee47a06da6e262d3;p=libc-test diff --git a/src/regression/inet_pton-empty-last-field.c b/src/regression/inet_pton-empty-last-field.c index eef44dc..b06fa11 100644 --- a/src/regression/inet_pton-empty-last-field.c +++ b/src/regression/inet_pton-empty-last-field.c @@ -1,16 +1,39 @@ -// '0' last field in an ipv6 address cannot be abbreviated to :: +// zero compression for the last field in an ipv6 address is (probably) allowed +// https://tools.ietf.org/html/rfc4291#section-2.2 +// but further fields shouldnt buffer overflow +#include #include #include #include "test.h" +static void txt(char *s, unsigned char *buf) +{ + int i; + sprintf(s, "%04x", buf[0]<<8 | buf[1]); + for (i=1; i<8; i++) + sprintf(s+5*i, ":%04x", buf[2*i]<<8 | buf[2*i+1]); +} + int main(void) { + char s[50], sw[50]; unsigned char buf[16]; - char addr[] = "1:2:3:4:5:6:7::"; + unsigned char want[16] = {0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,0}; + char *addr; + + addr = "1:2:3:4:5:6:7::"; + if (inet_pton(AF_INET6, addr, buf)!=1 || memcmp(buf, want, 16)!=0) { + txt(s, buf); + txt(sw, want); + t_error("inet_pton(%s) returned %s, wanted %s\n", + addr, s, sw); + } - if (inet_pton(AF_INET6, addr, buf)) { - t_error("inet_pton(%s) returned %x:%x:%x:%x:%x:%x:%x:%x, wanted a failure\n", - addr, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); + addr = "1:2:3:4:5:6:7::9:10:11:12:13:14:15:16:17:18:19:20"; + if (inet_pton(AF_INET6, addr, buf)!=0) { + txt(s, buf); + t_error("inet_pton(%s) returned %s, wanted a failure\n", + addr, s); } return t_status; }