]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
rule: json: fix returned string length
authorAlvaro Neira Ayuso <alvaroneay@gmail.com>
Wed, 25 Sep 2013 20:06:34 +0000 (22:06 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 25 Sep 2013 20:06:34 +0000 (22:06 +0200)
It was returning one byte more than the real string length.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/rule.c

index b4ce8f1c1966ddb51ab34d8b55d320004864b37a..5fd8814f12dbe156b3f98241755ff48d844b594c 100644 (file)
@@ -745,7 +745,9 @@ static int nft_rule_snprintf_json(char *buf, size_t size, struct nft_rule *r,
                SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
        }
-       ret = snprintf(buf+offset-1, len, "]}}");
+       /* Remove comma from last element */
+       offset--;
+       ret = snprintf(buf+offset, len, "]}}");
        SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
        return offset;