From 2e27ad8122fe20db802e1c7bb9d5f4ad6cd23665 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Mon, 22 Apr 2013 18:50:44 +0200 Subject: expr: catch missing and excess elements in concatenations # nft -nn filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh } :1:50-66: Error: datatype mismatch, expected concatenation of (IPv4 address, internet network service, internet network service), expression has type concatenation of (IPv4 address, internet network service) filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh } ^^^^^^^^^^^^^^^^^ # nft -nn filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh . ssh . ssh} :1:76-78: Error: unexpected concat component, expecting concatenation of (IPv4 address, internet network service, internet network service) filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh . ssh . ssh} ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^ Signed-off-by: Patrick McHardy --- src/datatype.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/datatype.c') diff --git a/src/datatype.c b/src/datatype.c index 3c17e929..2cb937f5 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -662,20 +662,23 @@ const struct datatype *concat_type_alloc(const struct expr *expr) { struct datatype *dtype; struct expr *i; - char desc[256] = "concatenation of "; - unsigned int type = 0; + char desc[256] = "concatenation of ("; + unsigned int type = 0, size = 0; list_for_each_entry(i, &expr->expressions, list) { - if (type != 0) + if (size != 0) strncat(desc, ", ", sizeof(desc) - strlen(desc) - 1); strncat(desc, i->dtype->desc, sizeof(desc) - strlen(desc) - 1); type <<= 8; type |= i->dtype->type; + size++; } + strncat(desc, ")", sizeof(desc) - strlen(desc) - 1); dtype = xzalloc(sizeof(*dtype)); dtype->type = type; + dtype->size = size; dtype->desc = xstrdup(desc); dtype->parse = concat_type_parse; -- cgit v1.2.3