Netfilter-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [nft PATCH] json: Fix memleak in set_dtype_json()
@ 2020-10-08 17:10 Phil Sutter
  2020-10-12 13:03 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Sutter @ 2020-10-08 17:10 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

Turns out json_string() already dups the input, so the temporary dup
passed to it is lost.

Fixes: e70354f53e9f6 ("libnftables: Implement JSON output support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/json.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/json.c b/src/json.c
index 121dfb247d967..a8824d3fc05a9 100644
--- a/src/json.c
+++ b/src/json.c
@@ -62,7 +62,7 @@ static json_t *set_dtype_json(const struct expr *key)
 
 	tok = strtok(namedup, " .");
 	while (tok) {
-		json_t *jtok = json_string(xstrdup(tok));
+		json_t *jtok = json_string(tok);
 		if (!root)
 			root = jtok;
 		else if (json_is_string(root))
-- 
2.28.0


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

* Re: [nft PATCH] json: Fix memleak in set_dtype_json()
  2020-10-08 17:10 [nft PATCH] json: Fix memleak in set_dtype_json() Phil Sutter
@ 2020-10-12 13:03 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2020-10-12 13:03 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel

On Thu, Oct 08, 2020 at 07:10:13PM +0200, Phil Sutter wrote:
> Turns out json_string() already dups the input, so the temporary dup
> passed to it is lost.

LGTM.

> Fixes: e70354f53e9f6 ("libnftables: Implement JSON output support")
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
>  src/json.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/json.c b/src/json.c
> index 121dfb247d967..a8824d3fc05a9 100644
> --- a/src/json.c
> +++ b/src/json.c
> @@ -62,7 +62,7 @@ static json_t *set_dtype_json(const struct expr *key)
>  
>  	tok = strtok(namedup, " .");
>  	while (tok) {
> -		json_t *jtok = json_string(xstrdup(tok));
> +		json_t *jtok = json_string(tok);
>  		if (!root)
>  			root = jtok;
>  		else if (json_is_string(root))
> -- 
> 2.28.0
> 

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08 17:10 [nft PATCH] json: Fix memleak in set_dtype_json() Phil Sutter
2020-10-12 13:03 ` Pablo Neira Ayuso

Netfilter-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netfilter-devel/0 netfilter-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netfilter-devel netfilter-devel/ https://lore.kernel.org/netfilter-devel \
		netfilter-devel@vger.kernel.org
	public-inbox-index netfilter-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netfilter-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git