From 2f408deee4d88ebd2ee87bbf5fe227ff764e0e6d Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Tue, 18 Aug 2026 22:05:20 -0400 Subject: rules: a rule set is not 64 kilobytes long fmtrules formatted into a 64K buffer with seprint, which clamps, and returned how much it had written. Nothing looked at whether that was everything. Since prepend, append and delete all work by formatting the whole set out, editing the text and parsing it back -- deliberately, so that a rule typed at ctl and a rule in a file go through one parser -- editing a set past the limit did not truncate the display, it truncated the rules. Measured with 2000 rules, about 104K formatted: and all of it comes back want: 2000 got: 1214 and survives an edit want: ok got: refused with nothing lost off the end got: 1214 786 rules gone from the running firewall, and the only sign is that the edit after it failed. save wrote the same short file, so reload would then have made the loss permanent. Now sized and allocated to fit. The bound is per rule -- the fixed attributes at their longest, plus the protocol, which is the only part whose length is ndb's choice rather than ours -- summed under the same lock that formats, so an install cannot get between the two passes. flows had the identical cap and gets the identical fix; on a busy firewall it is the file most likely to reach it. Rulebuf is gone. Six checks: a 2000-rule set loads, comes back whole, survives an edit, and saves whole. Co-Authored-By: Claude Opus 5 --- fw/src/rules.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'fw/src/rules.h') diff --git a/fw/src/rules.h b/fw/src/rules.h index f2c38d4..7d7fe1b 100644 --- a/fw/src/rules.h +++ b/fw/src/rules.h @@ -45,8 +45,8 @@ void readrules(char*); /* parse and install, fatal on error */ Rule* parserules(char*, char**); /* parse only; nil + reason on error */ void installrules(Rule*); /* swap in, then call rulechanged */ void freerules(Rule*); -long fmtrules(char*, long); /* current set, back in ndb form */ -long fmthits(char*, long); /* the same, with hit counts */ +char* rulestext(void); /* current set as ndb; free it */ +char* hitstext(void); /* the same, with hit counts */ void dumprules(void); void checklogging(void); /* -- cgit v1.2.3