pfctl: parser must not ignore error from pfctl_optimize_ruleset()

Ignoring the error may cause pfctl(8) to load inconsistent ruleset
preventing pf(4) to enforce desired policy.

Issue reported and fix suggested by berts _from_ fastmail _dot_ com

'Looks good.' @deraadt

MFC after:	1 week
Obtained from:	OpenBSD, sashan <sashan@openbsd.org>, 9fd28a8cca
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 343ace42f82a629374af4dc3a72da5f46f2c3feb)
This commit is contained in:
Kristof Provost 2026-03-22 03:50:47 +01:00 • committed by Franco Fichtner
parent 920990c75a
commit 55f031f303

View file

@ -1959,8 +1959,9 @@ pfctl_load_ruleset(struct pfctl *pf, char *path, struct pfctl_ruleset *rs,
}
if (pf->optimize && rs_num == PF_RULESET_FILTER)
pfctl_optimize_ruleset(pf, rs);
if (pf->optimize && rs_num == PF_RULESET_FILTER &&
(error = pfctl_optimize_ruleset(pf, rs)) != 0)
goto error;
while ((r = TAILQ_FIRST(rs->rules[rs_num].active.ptr)) != NULL) {
TAILQ_REMOVE(rs->rules[rs_num].active.ptr, r, entries);