diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c --- a/sbin/pfctl/pfctl.c +++ b/sbin/pfctl/pfctl.c @@ -3026,6 +3026,7 @@ int ret; memset(&pr, 0, sizeof(pr)); + strlcpy(pr.path, anchor, sizeof(pr.path)); if ((ret = pfctl_get_rulesets(pfh, anchor, &mnr)) != 0) errx(1, "%s", pf_strerror(ret)); for (nr = 0; nr < mnr; ++nr) { diff --git a/tests/sys/netpfil/pf/anchor.sh b/tests/sys/netpfil/pf/anchor.sh --- a/tests/sys/netpfil/pf/anchor.sh +++ b/tests/sys/netpfil/pf/anchor.sh @@ -123,6 +123,42 @@ pft_cleanup } +atf_test_case "multiple_nested" "cleanup" +multiple_nested_head() +{ + atf_set descr 'Test setting and retrieving multiple nested anchors' + atf_set require.user root +} + +multiple_nested_body() +{ + pft_init + + epair=$(vnet_mkepair) + vnet_mkjail alcatraz ${epair}a + + pft_set_rules alcatraz \ + "anchor \"foo\" { \n\ + anchor \"bar\" { \n\ + pass on ${epair}a \n\ + } \n\ + anchor \"baz\" { \n\ + pass on ${epair}a \n\ + } \n\ + }" + + atf_check -s exit:0 -o inline:" foo\n foo/bar\n foo/baz\n" \ + -e ignore jexec alcatraz pfctl -sA + + atf_check -s exit:0 -o inline:" foo/bar\n foo/baz\n" \ + -e ignore jexec alcatraz pfctl -a foo -sA +} + +multiple_nested_cleanup() +{ + pft_cleanup +} + atf_test_case "wildcard" "cleanup" wildcard_head() { @@ -498,6 +534,7 @@ atf_add_test_case "pr183198" atf_add_test_case "pr279225" atf_add_test_case "nested_anchor" + atf_add_test_case "multiple_nested" atf_add_test_case "wildcard" atf_add_test_case "nested_label" atf_add_test_case "quick"