]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
utils: nft_fprintf: prevent an empty buffer from being printed
authorArturo Borrero <arturo.borrero.glez@gmail.com>
Fri, 12 Sep 2014 19:41:25 +0000 (21:41 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 16 Sep 2014 17:04:06 +0000 (19:04 +0200)
If the snprintf_cb() printed 0 characters, no \0 exists in the buffer.
Also, in that case fprintf() is meant to print nothing, so we can just exit.

This patch addresses new cases of textual output by libnftnl with trash.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/utils.c

index 96c8bf22fc7a1a1c0e0a157fcb882f6013bf54df..d70fbf1262ec0415a72e055fc2662c801c1dea3b 100644 (file)
@@ -190,7 +190,7 @@ int nft_fprintf(FILE *fp, void *obj, uint32_t type, uint32_t flags,
        int ret;
 
        ret = snprintf_cb(buf, bufsiz, obj, type, flags);
-       if (ret < 0)
+       if (ret <= 0)
                goto out;
 
        if (ret >= NFT_SNPRINTF_BUFSIZ) {
@@ -201,7 +201,7 @@ int nft_fprintf(FILE *fp, void *obj, uint32_t type, uint32_t flags,
                        return -1;
 
                ret = snprintf_cb(buf, bufsiz, obj, type, flags);
-               if (ret < 0)
+               if (ret <= 0)
                        goto out;
        }