From 788c986343bc24bd0272e8aa409121ffe51f1ef3 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 15 Aug 2016 13:14:18 +0200 Subject: 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 --- src/datatype.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/datatype.c') 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, -- cgit v1.2.3