netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [libnftnl PATCH] utils: Don't return directly from SNPRINTF_BUFFER_SIZE
@ 2016-08-12 12:39 Phil Sutter
  2016-08-12 13:37 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Sutter @ 2016-08-12 12:39 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel, Phil Sutter, Arturo Borrero

From: Phil Sutter <psutter@redhat.com>

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>
---
This is actually v2 of "[libnftnl PATCH 2/7] ruleset: Prevent memleak in
nftnl_ruleset_snprintf_*() functions" but since it's a completely
different approach there was no use in keeping the old subject line.
---
 include/utils.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/utils.h b/include/utils.h
index 21694b6ab1912..924df324aa603 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -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;				\
-- 
2.8.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [libnftnl PATCH] utils: Don't return directly from SNPRINTF_BUFFER_SIZE
  2016-08-12 12:39 [libnftnl PATCH] utils: Don't return directly from SNPRINTF_BUFFER_SIZE Phil Sutter
@ 2016-08-12 13:37 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2016-08-12 13:37 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel, Phil Sutter, Arturo Borrero

On Fri, Aug 12, 2016 at 02:39:50PM +0200, Phil Sutter wrote:
> From: Phil Sutter <psutter@redhat.com>
> 
> 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).

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-12 13:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-12 12:39 [libnftnl PATCH] utils: Don't return directly from SNPRINTF_BUFFER_SIZE Phil Sutter
2016-08-12 13:37 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).