git: 4ee6a830d6c1 - main - pf: Fix a use of an uninitialized variable

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sun, 03 Nov 2024 16:48:07 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=4ee6a830d6c191c1c420b6764a4d388f756168d3

commit 4ee6a830d6c191c1c420b6764a4d388f756168d3
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-11-03 14:36:39 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-11-03 16:46:53 +0000

    pf: Fix a use of an uninitialized variable
    
    pf_find_state_all() expects the caller to initialize "*more" if it is
    non-NULL, but pf_handle_natlook() didn't obey this protocol.  Follow the
    pattern from OpenBSD and initialize it in the caller.
    
    Also make pf_find_state_all() unconditionally initialize "*more" for
    good measure.
    
    Fixes:          71d3c7041d70 ("pf: convert DIOCNATLOOK to netlink")
    Reported by:    KMSAN
    Reviewed by:    kp
    Differential Revision:  https://reviews.freebsd.org/D47405
---
 sys/netpfil/pf/pf.c    | 3 +++
 sys/netpfil/pf/pf_nl.c | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index a98baeb4bdec..17614e1a9995 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -1798,6 +1798,9 @@ pf_find_state_all(const struct pf_state_key_cmp *key, u_int dir, int *more)
 	struct pf_kstate	*s, *ret = NULL;
 	int			 idx, inout = 0;
 
+	if (more != NULL)
+		*more = 0;
+
 	pf_counter_u64_add(&V_pf_status.fcounters[FCNT_STATE_SEARCH], 1);
 
 	kh = &V_pf_keyhash[pf_hashkey((const struct pf_state_key *)key)];
diff --git a/sys/netpfil/pf/pf_nl.c b/sys/netpfil/pf/pf_nl.c
index 67047a319fb8..1da9bead394b 100644
--- a/sys/netpfil/pf/pf_nl.c
+++ b/sys/netpfil/pf/pf_nl.c
@@ -1264,7 +1264,7 @@ pf_handle_natlook(struct nlmsghdr *hdr, struct nl_pstate *npt)
 	struct pf_state_key	*sk;
 	struct pf_kstate	*state;
 	struct genlmsghdr	*ghdr_new;
-	int			 error, m;
+	int			 error, m = 0;
 	int			 sidx, didx;
 
 	error = nl_parse_nlmsg(hdr, &natlook_parser, npt, &attrs);