All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [nft PATCH 3/9] parser_json: Proper ct expectation attribute parsing
Date: Wed, 20 Sep 2023 22:57:21 +0200	[thread overview]
Message-ID: <20230920205727.22103-4-phil@nwl.cc> (raw)
In-Reply-To: <20230920205727.22103-1-phil@nwl.cc>

Parts of the code were unsafe (parsing 'I' format into uint32_t), the
rest just plain wrong (parsing 'o' format into char *tmp). Introduce a
temporary int variable to parse into.

Fixes: 1dd08fcfa07a4 ("src: add ct expectations support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/parser_json.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/parser_json.c b/src/parser_json.c
index 045bee1d8edaa..92168b9ab580e 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -3447,8 +3447,8 @@ static struct cmd *json_parse_cmd_add_object(struct json_ctx *ctx,
 {
 	const char *family, *tmp, *rate_unit = "packets", *burst_unit = "bytes";
 	uint32_t l3proto = NFPROTO_UNSPEC;
+	int inv = 0, flags = 0, i;
 	struct handle h = { 0 };
-	int inv = 0, flags = 0;
 	struct obj *obj;
 	json_t *jflags;
 
@@ -3599,11 +3599,12 @@ static struct cmd *json_parse_cmd_add_object(struct json_ctx *ctx,
 				return NULL;
 			}
 		}
-		if (!json_unpack(root, "{s:o}", "dport", &tmp))
-			obj->ct_expect.dport = atoi(tmp);
-		json_unpack(root, "{s:I}", "timeout", &obj->ct_expect.timeout);
-		if (!json_unpack(root, "{s:o}", "size", &tmp))
-			obj->ct_expect.size = atoi(tmp);
+		if (!json_unpack(root, "{s:i}", "dport", &i))
+			obj->ct_expect.dport = i;
+		if (!json_unpack(root, "{s:i}", "timeout", &i))
+			obj->ct_expect.timeout = i;
+		if (!json_unpack(root, "{s:i}", "size", &i))
+			obj->ct_expect.size = i;
 		break;
 	case CMD_OBJ_LIMIT:
 		obj->type = NFT_OBJECT_LIMIT;
-- 
2.41.0


  parent reply	other threads:[~2023-09-20 20:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20 20:57 [nft PATCH 0/9] Misc JSON parser fixes Phil Sutter
2023-09-20 20:57 ` [nft PATCH 1/9] parser_json: Catch wrong "reset" payload Phil Sutter
2023-09-20 20:57 ` [nft PATCH 2/9] parser_json: Fix typo in json_parse_cmd_add_object() Phil Sutter
2023-09-20 20:57 ` Phil Sutter [this message]
2023-09-20 20:57 ` [nft PATCH 4/9] parser_json: Fix flowtable prio value parsing Phil Sutter
2023-09-20 20:57 ` [nft PATCH 5/9] parser_json: Fix limit object burst " Phil Sutter
2023-09-20 20:57 ` [nft PATCH 6/9] parser_json: Fix synproxy object mss/wscale parsing Phil Sutter
2023-09-20 20:57 ` [nft PATCH 7/9] parser_json: Wrong check in json_parse_ct_timeout_policy() Phil Sutter
2023-09-20 20:57 ` [nft PATCH 8/9] parser_json: Catch nonsense ops in match statement Phil Sutter
2023-09-20 20:57 ` [nft PATCH 9/9] parser_json: Default meter size to zero Phil Sutter
2023-09-22  8:56 ` [nft PATCH 0/9] Misc JSON parser fixes Phil Sutter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230920205727.22103-4-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.