git: 40c611d0939f - main - pfctl: fix incorrect errno checks
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 15 Jul 2026 13:50:36 UTC
The branch main has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=40c611d0939f187d9a211e9e497291e251deddd3
commit 40c611d0939f187d9a211e9e497291e251deddd3
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2026-07-14 07:32:41 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2026-07-15 11:44:59 +0000
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")
---
sbin/pfctl/pfctl_table.c | 19 +++++++++++++++----
1 file 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);