ref: d551a83ae4e3e42c4d7da9638ec1f937200844cb
parent: 7102a23245a07bf0a9517b3731f70e0475daf39b
author: cinap_lenrek <[email protected]>
date: Tue Feb 12 16:43:22 EST 2019
libip: return -1 in parseipmask() and parseipandmask() when mask is not ipv4 and v4 argument was set
--- a/sys/src/libip/parseip.c
+++ b/sys/src/libip/parseip.c
@@ -112,7 +112,7 @@
}
if(v4){
to[10] = to[11] = 0xff;
- return nhgetl(to + IPv4off);
+ return (ulong)nhgetl(to + IPv4off);
} else
return 6;
}
@@ -124,8 +124,8 @@
vlong
parseipmask(uchar *to, char *from, int v4)
{
- int i, w;
vlong x;
+ int i, w;
uchar *p;
if(*from == '/'){
@@ -148,16 +148,16 @@
* (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 @@
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;
}