Skip to content

Commit 0f0662c

Browse files
committed
pf: Fix error handling in pf_handle_get_tstats()
- pfr_table_count() can return an error. - We must check for failure from mallocarray(M_NOWAIT). Fixes: 9e8d296 ("pf: convert DIOCRGETTSTATS to netlink") Reported by: Kevin Day <[email protected]> Reviewed by: kp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54094
1 parent 73586fc commit 0f0662c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sys/netpfil/pf/pf_nl.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,8 +1954,18 @@ pf_handle_get_tstats(struct nlmsghdr *hdr, struct nl_pstate *npt)
19541954
PF_RULES_RLOCK();
19551955

19561956
n = pfr_table_count(&attrs.pfrio_table, attrs.pfrio_flags);
1957+
if (n < 0) {
1958+
PF_RULES_RUNLOCK();
1959+
PF_TABLE_STATS_UNLOCK();
1960+
return (EINVAL);
1961+
}
19571962
pfrtstats = mallocarray(n,
19581963
sizeof(struct pfr_tstats), M_PF, M_NOWAIT | M_ZERO);
1964+
if (pfrtstats == NULL) {
1965+
PF_RULES_RUNLOCK();
1966+
PF_TABLE_STATS_UNLOCK();
1967+
return (ENOMEM);
1968+
}
19591969

19601970
error = pfr_get_tstats(&attrs.pfrio_table, pfrtstats,
19611971
&n, attrs.pfrio_flags | PFR_FLAG_USERIOCTL);

0 commit comments

Comments
 (0)