]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
utils: Don't return directly from SNPRINTF_BUFFER_SIZE
authorPhil Sutter <psutter@redhat.com>
Fri, 12 Aug 2016 12:39:50 +0000 (14:39 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 12 Aug 2016 13:36:04 +0000 (15:36 +0200)
Apart from being a bad idea in general, the return statement contained
in that macro in some cases leads to returning from functions without
properly cleaning up, thereby causing memory leaks.

Instead, just sanitize the value in 'ret' to not harm further calls of
snprintf() (as 'len' will eventually just become zero).

Cc: Arturo Borrero <arturo.borrero.glez@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/utils.h

index 21694b6ab19126be369b3e599fff8194dcb1d13b..924df324aa60342f6cbd8f8b62a80906fab84656 100644 (file)
@@ -54,7 +54,7 @@ void __nftnl_assert_attr_exists(uint16_t attr, uint16_t attr_max,
 
 #define SNPRINTF_BUFFER_SIZE(ret, size, len, offset)   \
        if (ret < 0)                                    \
-               return ret;                             \
+               ret = 0;                                \
        offset += ret;                                  \
        if (ret > len)                                  \
                ret = len;                              \