From: James Prestwood <prestwoj at gmail.com>
To: iwd at lists.01.org
Subject: [PATCH 4/5] json: restrict json_iter_{parse,next} to objects/arrays
Date: Thu, 06 Jan 2022 14:42:15 -0800 [thread overview]
Message-ID: <20220106224216.569171-4-prestwoj@gmail.com> (raw)
In-Reply-To: 20220106224216.569171-1-prestwoj@gmail.com
[-- Attachment #1: Type: text/plain, Size: 994 bytes --]
json_iter_parse is only meant to work on objects while
json_iter_next is only meant to work on arrays.
This adds checks in both APIs to ensure they aren't being
used incorrectly.
---
src/json.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/json.c b/src/json.c
index 0942dae3..869a3f43 100644
--- a/src/json.c
+++ b/src/json.c
@@ -200,6 +200,9 @@ bool json_iter_parse(struct json_iter *iter, enum json_type type, ...)
if (iter->start == -1)
return false;
+ if (c->tokens[iter->start].type != JSMN_OBJECT)
+ return false;
+
args = l_queue_new();
va_start(va, type);
@@ -427,6 +430,9 @@ bool json_iter_next(struct json_iter *iter)
jsmntok_t *t = c->tokens + iter->current;
int inc = 1;
+ if (iter->current == iter->start && t->type != JSMN_ARRAY)
+ return false;
+
/*
* If this is the initial iteration skip this and just increment
* current by 1 since this iterator points to a container which needs to
--
2.31.1
reply other threads:[~2022-01-06 22:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220106224216.569171-4-prestwoj@gmail.com \
--to=iwd@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox