diff --git a/sys/net/ipfw3/ip_fw3.c b/sys/net/ipfw3/ip_fw3.c
--- a/sys/net/ipfw3/ip_fw3.c
+++ b/sys/net/ipfw3/ip_fw3.c
@@ -847,6 +847,8 @@
struct netmsg_base *nmsg;
int *rulenum;
+ if (sopt->sopt_valsize < sizeof(int))
+ return EINVAL;
rulenum = (int *) sopt->sopt_val;