In ipfw2, avoid left-shifting negative integers, which is undefined.

While here, make some other arguments to htonl(3) unsigned too.

MFC after:	3 days
This commit is contained in:
Dimitry Andric 2015-08-12 21:07:57 +00:00
parent e8bac3f240
commit dbe90f04b4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=286702

View File

@ -2869,14 +2869,14 @@ fill_ip(ipfw_insn_ip *cmd, char *av, int cblen, struct tidx *tstate)
case '/':
masklen = atoi(p);
if (masklen == 0)
d[1] = htonl(0); /* mask */
d[1] = htonl(0U); /* mask */
else if (masklen > 32)
errx(EX_DATAERR, "bad width ``%s''", p);
else
d[1] = htonl(~0 << (32 - masklen));
d[1] = htonl(~0U << (32 - masklen));
break;
case '{': /* no mask, assume /24 and put back the '{' */
d[1] = htonl(~0 << (32 - 24));
d[1] = htonl(~0U << (32 - 24));
*(--p) = md;
break;
@ -2885,7 +2885,7 @@ fill_ip(ipfw_insn_ip *cmd, char *av, int cblen, struct tidx *tstate)
/* FALLTHROUGH */
case 0: /* initialization value */
default:
d[1] = htonl(~0); /* force /32 */
d[1] = htonl(~0U); /* force /32 */
break;
}
d[0] &= d[1]; /* mask base address with mask */