diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-02-12 21:43:22 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-02-12 21:43:22 +0100 |
commit | d551a83ae4e3e42c4d7da9638ec1f937200844cb (patch) | |
tree | dcfdeee864c2dc7de210e5abfc07579a19992a4f /sys/src/libip | |
parent | 7102a23245a07bf0a9517b3731f70e0475daf39b (diff) |
libip: return -1 in parseipmask() and parseipandmask() when mask is not ipv4 and v4 argument was set
Diffstat (limited to 'sys/src/libip')
-rw-r--r-- | sys/src/libip/parseip.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/sys/src/libip/parseip.c b/sys/src/libip/parseip.c index 757716770..ab7bfe0c8 100644 --- a/sys/src/libip/parseip.c +++ b/sys/src/libip/parseip.c @@ -112,7 +112,7 @@ parseip(uchar *to, char *from) } if(v4){ to[10] = to[11] = 0xff; - return nhgetl(to + IPv4off); + return (ulong)nhgetl(to + IPv4off); } else return 6; } @@ -124,8 +124,8 @@ parseip(uchar *to, char *from) vlong parseipmask(uchar *to, char *from, int v4) { - int i, w; vlong x; + int i, w; uchar *p; if(*from == '/'){ @@ -148,16 +148,16 @@ parseipmask(uchar *to, char *from, int v4) * (because it has too few mask bits). Arguably, we could * always return 6 here. */ - if (w < 8*(IPaddrlen-IPv4addrlen)) - return 6; - x = nhgetl(to+IPv4off); + if (w < 96) + return v4 ? -1 : 6; + x = (ulong)nhgetl(to+IPv4off); } else { /* as a straight v4 bit mask */ x = parseip(to, from); - if (x != -1) - x = (ulong)nhgetl(to + IPv4off); if(memcmp(to, v4prefix, IPv4off) == 0) memset(to, 0xff, IPv4off); + else if(v4) + x = -1; } return x; } @@ -168,9 +168,9 @@ parseipandmask(uchar *ip, uchar *mask, char *ipstr, char *maskstr) vlong x; x = parseip(ip, ipstr); - if(x == -1) - return -1; - if(maskstr == nil || parseipmask(mask, maskstr, memcmp(ip, v4prefix, IPv4off) == 0) == -1) + if(maskstr == nil) memset(mask, 0xff, IPaddrlen); + else if(parseipmask(mask, maskstr, memcmp(ip, v4prefix, IPv4off) == 0) == -1) + x = -1; return x; } |