]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: Reject quoted strings containing only wildcard
authorPhil Sutter <phil@nwl.cc>
Thu, 24 Sep 2020 15:38:45 +0000 (17:38 +0200)
committerPhil Sutter <phil@nwl.cc>
Tue, 6 Oct 2020 15:55:54 +0000 (17:55 +0200)
Fix for an assertion fail when trying to match against an all-wildcard
interface name:

| % nft add rule t c iifname '"*"'
| nft: expression.c:402: constant_expr_alloc: Assertion `(((len) + (8) - 1) / (8)) > 0' failed.
| zsh: abort      nft add rule t c iifname '"*"'

Fix this by detecting the string in expr_evaluate_string() and returning
an error message:

| % nft add rule t c iifname '"*"'
| Error: All-wildcard strings are not supported
| add rule t c iifname "*"
|                      ^^^

While being at it, drop the 'datalen >= 1' clause from the following
conditional as together with the added check for 'datalen == 0', all
possible other values have been caught already.

src/evaluate.c

index c8045e5ded729fa375b3d5f9cdf191f6f46eafed..5f17d7501ac0ee7f33093e5649c3e9d5281b8e3d 100644 (file)
@@ -324,8 +324,11 @@ static int expr_evaluate_string(struct eval_ctx *ctx, struct expr **exprp)
                return 0;
        }
 
-       if (datalen >= 1 &&
-           data[datalen - 1] == '\\') {
+       if (datalen == 0)
+               return expr_error(ctx->msgs, expr,
+                                 "All-wildcard strings are not supported");
+
+       if (data[datalen - 1] == '\\') {
                char unescaped_str[data_len];
 
                memset(unescaped_str, 0, sizeof(unescaped_str));