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