summaryrefslogtreecommitdiffstats
path: root/src/datatype.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2016-08-15 13:14:18 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2016-08-18 03:14:08 +0200
commit788c986343bc24bd0272e8aa409121ffe51f1ef3 (patch)
tree42cf0210e9fce93e0a5a951f0012e891fa750b05 /src/datatype.c
parentddb1f1f8cdca2e0f70254a5adcc0291907503a36 (diff)
src: quote user-defined strings when used from rule selectors
The following selectors display strings using quotes: * meta iifname * meta oifname * meta ibriport * meta obriport However, the following do not: * meta oif * meta iif * meta skuid * meta skgid * meta iifgroup * meta oifgroup * meta rtclassid * ct label Given they refer to user-defined values, neither keywords nor internal built-in known values, let's quote the output of this. This patch modifies symbolic_constant_print() so we can signal this to indicate if the string needs to be quoted. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/datatype.c')
-rw-r--r--src/datatype.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/datatype.c b/src/datatype.c
index 002c4c66..2b1619a6 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -86,7 +86,8 @@ void datatype_print(const struct expr *expr)
if (dtype->print != NULL)
return dtype->print(expr);
if (dtype->sym_tbl != NULL)
- return symbolic_constant_print(dtype->sym_tbl, expr);
+ return symbolic_constant_print(dtype->sym_tbl, expr,
+ false);
} while ((dtype = dtype->basetype));
BUG("datatype %s has no print method or symbol table\n",
@@ -154,7 +155,7 @@ out:
}
void symbolic_constant_print(const struct symbol_table *tbl,
- const struct expr *expr)
+ const struct expr *expr, bool quotes)
{
unsigned int len = div_round_up(expr->len, BITS_PER_BYTE);
const struct symbolic_constant *s;
@@ -173,7 +174,10 @@ void symbolic_constant_print(const struct symbol_table *tbl,
if (s->identifier == NULL)
return expr_basetype(expr)->print(expr);
- printf("%s", s->identifier);
+ if (quotes)
+ printf("\"%s\"", s->identifier);
+ else
+ printf("%s", s->identifier);
}
void symbol_table_print(const struct symbol_table *tbl,
@@ -684,7 +688,7 @@ static void __exit mark_table_exit(void)
static void mark_type_print(const struct expr *expr)
{
- return symbolic_constant_print(mark_tbl, expr);
+ return symbolic_constant_print(mark_tbl, expr, true);
}
static struct error_record *mark_type_parse(const struct expr *sym,