Blob Blame History Raw
From 7413de9ca21bcb7c3de2af37c99ab858615430fc Mon Sep 17 00:00:00 2001
From: Phil Sutter <psutter@redhat.com>
Date: Tue, 16 May 2017 12:28:55 +0200
Subject: [PATCH] utils: Don't return directly from SNPRINTF_BUFFER_SIZE

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1353311
Upstream Status: libnftnl commit 9afae310b019a

commit 9afae310b019aa497afb94833afc9a936bc38a1f
Author: Phil Sutter <psutter@redhat.com>
Date:   Fri Aug 12 14:39:50 2016 +0200

    utils: Don't return directly from SNPRINTF_BUFFER_SIZE

    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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/utils.h b/include/utils.h
index 46ff18a..ae596c5 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -45,7 +45,7 @@ void __nftnl_assert_fail(uint16_t attr, const char *filename, int line);
 
 #define SNPRINTF_BUFFER_SIZE(ret, size, len, offset)	\
 	if (ret < 0)					\
-		return ret;				\
+		ret = 0;				\
 	offset += ret;					\
 	if (ret > len)					\
 		ret = len;				\
-- 
1.8.3.1