Skip to contentSkip to conversation

nftables: bug fixes and minor cleanups

PATCH New Patrick McHardy 1 participant 5 messages Jan 10, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

cover nftables: bug fixes and minor cleanups

The following four patches fix error reporting for errors starting at column 0, fix a crash for unresolvable mark values, revert the incorrect integer_type parsing patch and reduce the size of the "could not process rule in batch" message to avoid having it spill over on the next line.

If there are no objections, I'll push them to master in a few hours.

#1 lore raw

PATCH 1/4 nftables: shorten "could not process rule in batch" message

Remove the "in batch" part, it makes most messages exceed a single line, the user doesn't care about this and we process even single rules in "batches".

---
 src/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/main.c +2 -2
index 32a991a..e8be423 100644
@@ -183,8 +183,8 @@ static int nft_netlink(struct parser_state *state, struct list_head *msgs)
 			if (err->seqnum == cmd->seqnum ||
 			    err->seqnum == batch_seqnum) {
 				netlink_io_error(&ctx, &cmd->location,
-					"Could not process rule in batch: %s",
-					strerror(err->err));
+						 "Could not process rule: %s",
+						 strerror(err->err));
 				if (err->seqnum == cmd->seqnum) {
 					mnl_err_list_free(err);
 					break;
Signature · 1 line
1.8.4.2
#2 lore raw

PATCH 2/4 erec: fix error markup for errors starting at column 0

In reply to Patrick McHardy

For errors starting at column 0, we must not subtract 1 to avoid underflow.

---
 src/erec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/erec.c +2 -1
index 7451d94..a157d2f 100644
@@ -138,7 +138,8 @@ void erec_print(FILE *f, const struct error_record *erec)
 		end = 0;
 		for (l = erec->num_locations - 1; l >= 0; l--) {
 			loc = &erec->locations[l];
-			for (i = loc->first_column - 1; i < loc->last_column; i++)
+			for (i = loc->first_column ? loc->first_column - 1 : 0;
+			     i < loc->last_column; i++)
 				buf[i] = l ? '~' : '^';
 			end = max(end, loc->last_column);
 		}
Signature · 1 line
1.8.4.2
#3 lore raw

PATCH 3/4 datatype: revert "fix crash if wrong integer type is passed"

In reply to Patrick McHardy

Revert commit a320531e7:

We have generic type checks that handle this case just fine and indeed the bugzilla entry mentioned in the reverted patch states:

BUG: invalid input descriptor type 538976288

nft: src/erec.c:100: erec_print: Assertion `0' failed. Abandon

So the problem is not related to datatypes at all and generic type checking works perfectly fine:

<cmdline>:1:52-57: Error: datatype mismatch, expected Ethernet protocol, expression has type Internet protocol add rule ip6 filter input position 4 meta protocol icmpv6 accept

                                     ~~~~~~~~~~~~~ ^^^^^^
---
 src/datatype.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
src/datatype.c +2 -4
index 2e5788d..9910a1b 100644
@@ -230,10 +230,8 @@ static struct error_record *integer_type_parse(const struct expr *sym,
 	if (gmp_sscanf(sym->identifier, "%Zu%n", v, &len) != 1 ||
 	    (int)strlen(sym->identifier) != len) {
 		mpz_clear(v);
-		if (sym->dtype != &integer_type) {
-			return error(&sym->location, "This is not a valid %s",
-				     sym->dtype->desc);
-		}
+		if (sym->dtype != &integer_type)
+			return NULL;
 		return error(&sym->location, "Could not parse %s",
 			     sym->dtype->desc);
 	}
Signature · 1 line
1.8.4.2
#4 lore raw

PATCH 4/4 meta: fix crash when parsing unresolvable mark values

In reply to Patrick McHardy

*res has undefined contents, set to NULL before invoking the parse function to make sure the test for != NULL doesn't falsely return true.

---
 src/datatype.c | 1 +
 1 file changed, 1 insertion(+)
src/datatype.c +1 -0
index 9910a1b..86ea80e 100644
@@ -643,6 +643,7 @@ static struct error_record *mark_type_parse(const struct expr *sym,
 		}
 	}
 
+	*res = NULL;
 	erec = sym->dtype->basetype->parse(sym, res);
 	if (erec != NULL)
 		return erec;
Signature · 1 line
1.8.4.2