Blame SOURCES/0065-parser_json-Fix-for-memleak-in-tcp-option-error-path.patch

8ff5ad
From 99d51194569f2784261f452ee821c42c3a7a6808 Mon Sep 17 00:00:00 2001
8ff5ad
From: Phil Sutter <psutter@redhat.com>
8ff5ad
Date: Wed, 6 Oct 2021 17:32:04 +0200
8ff5ad
Subject: [PATCH] parser_json: Fix for memleak in tcp option error path
8ff5ad
8ff5ad
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1999059
8ff5ad
Upstream Status: nftables commit f7b0eef8391ae
8ff5ad
8ff5ad
commit f7b0eef8391ae7f89a3a82f6eeecaebe199224d7
8ff5ad
Author: Phil Sutter <phil@nwl.cc>
8ff5ad
Date:   Fri Jun 11 16:07:02 2021 +0200
8ff5ad
8ff5ad
    parser_json: Fix for memleak in tcp option error path
8ff5ad
8ff5ad
    If 'kind' value is invalid, the function returned without freeing 'expr'
8ff5ad
    first. Fix this by performing the check before allocation.
8ff5ad
8ff5ad
    Fixes: cb21869649208 ("json: tcp: add raw tcp option match support")
8ff5ad
    Signed-off-by: Phil Sutter <phil@nwl.cc>
8ff5ad
---
8ff5ad
 src/parser_json.c | 6 +++---
8ff5ad
 1 file changed, 3 insertions(+), 3 deletions(-)
8ff5ad
8ff5ad
diff --git a/src/parser_json.c b/src/parser_json.c
8ff5ad
index ef4d4fb..2250be9 100644
8ff5ad
--- a/src/parser_json.c
8ff5ad
+++ b/src/parser_json.c
8ff5ad
@@ -610,12 +610,12 @@ static struct expr *json_parse_tcp_option_expr(struct json_ctx *ctx,
8ff5ad
 			"base", &kind, "offset", &offset, "len", &len)) {
8ff5ad
 		uint32_t flag = 0;
8ff5ad
 
8ff5ad
-		expr = tcpopt_expr_alloc(int_loc, kind,
8ff5ad
-					 TCPOPT_COMMON_KIND);
8ff5ad
-
8ff5ad
 		if (kind < 0 || kind > 255)
8ff5ad
 			return NULL;
8ff5ad
 
8ff5ad
+		expr = tcpopt_expr_alloc(int_loc, kind,
8ff5ad
+					 TCPOPT_COMMON_KIND);
8ff5ad
+
8ff5ad
 		if (offset == TCPOPT_COMMON_KIND && len == 8)
8ff5ad
 			flag = NFT_EXTHDR_F_PRESENT;
8ff5ad
 
8ff5ad
-- 
8ff5ad
2.31.1
8ff5ad