aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2026-07-14 07:32:41 +0000
committerKristof Provost <kp@FreeBSD.org>2026-07-15 11:44:59 +0000
commit40c611d0939f187d9a211e9e497291e251deddd3 (patch)
treece11e299fbd3c41ad6b6e1f2a8b61f89179a8cec
parentddbf89234312791e65991efff39a18a9e8e4d077 (diff)
pfctl: fix incorrect errno checks
These calls return an error value, they do not set errno. Check their return values. Sponsored by: Rubicon Communications, LLC ("Netgate")
-rw-r--r--sbin/pfctl/pfctl_table.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/sbin/pfctl/pfctl_table.c b/sbin/pfctl/pfctl_table.c
index aec02c493f1b..1af1538387c7 100644
--- a/sbin/pfctl/pfctl_table.c
+++ b/sbin/pfctl/pfctl_table.c
@@ -74,6 +74,17 @@ static const char *istats_text[2][2][2] = {
{ { "In6/Pass:", "In6/Block:" }, { "Out6/Pass:", "Out6/Block:" } }
};
+#define RETTEST(fct) do { \
+ int _ret; \
+ if ((!(opts & PF_OPT_NOACTION) || \
+ (opts & PF_OPT_DUMMYACTION)) && \
+ (_ret = (fct) != 0)) { \
+ if ((opts & PF_OPT_RECURSE) == 0) \
+ warnx("%s", pf_strerror(_ret)); \
+ goto _error; \
+ } \
+ } while (0)
+
#define RVTEST(fct) do { \
if ((!(opts & PF_OPT_NOACTION) || \
(opts & PF_OPT_DUMMYACTION)) && \
@@ -157,7 +168,7 @@ pfctl_table(int argc, char *argv[], char *tname, const char *command,
if (!strcmp(command, "-F")) {
if (argc || file != NULL)
usage();
- RVTEST(pfctl_clear_tables(pfh, &table, &ndel, flags));
+ RETTEST(pfctl_clear_tables(pfh, &table, &ndel, flags));
xprintf(opts, "%d tables deleted", ndel);
} else if (!strcmp(command, "-s")) {
b.pfrb_type = (opts & PF_OPT_VERBOSE2) ?
@@ -192,12 +203,12 @@ pfctl_table(int argc, char *argv[], char *tname, const char *command,
} else if (!strcmp(command, "kill")) {
if (argc || file != NULL)
usage();
- RVTEST(pfr_del_table(&table, &ndel, flags));
+ RETTEST(pfr_del_table(&table, &ndel, flags));
xprintf(opts, "%d table deleted", ndel);
} else if (!strcmp(command, "flush")) {
if (argc || file != NULL)
usage();
- RVTEST(pfr_clr_addrs(&table, &ndel, flags));
+ RETTEST(pfr_clr_addrs(&table, &ndel, flags));
xprintf(opts, "%d addresses deleted", ndel);
} else if (!strcmp(command, "add")) {
b.pfrb_type = PFRB_ADDRS;
@@ -390,7 +401,7 @@ pfctl_table(int argc, char *argv[], char *tname, const char *command,
opts & PF_OPT_USEDNS);
} else if (!strcmp(command, "zero")) {
flags |= PFR_FLAG_ADDRSTOO;
- RVTEST(pfctl_clear_tstats(pfh, &table, &nzero, flags));
+ RETTEST(pfctl_clear_tstats(pfh, &table, &nzero, flags));
xprintf(opts, "%d table/stats cleared", nzero);
} else
warnx("pfctl_table: unknown command '%s'", command);