fix regression: restore balanced nodes check for , - json2tsv - JSON to TSV converter
(HTM) git clone git://git.codemadness.org/json2tsv
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 33c1ceffbcb04f8a6970d04841175f96737942bb
(DIR) parent 69c080a4b190ea29c0dd1ae008c84cbd0712068f
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Tue, 22 Oct 2019 23:37:24 +0200
fix regression: restore balanced nodes check for ,
The EXPECT_END state contained ',' which did not check the depth.
reproduce:
echo '"test",' | json2tsv
This wrote nodes[-1].index++ and was treated as valid.
a primitive followed by , was also valid (incorrect), for example:
"true,"
EXPECT_END is "}]," All these states are checked now for the depth <= 0 so
remove the EXPECT_NOTHING state.
Diffstat:
M json.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
---
(DIR) diff --git a/json.c b/json.c
@@ -82,7 +82,6 @@ capacity(char **value, size_t *sz, size_t cur, size_t inc)
#define EXPECT_VALUE "{[\"-0123456789tfn"
#define EXPECT_STRING "\""
#define EXPECT_END "}],"
-#define EXPECT_NOTHING ""
#define EXPECT_OBJECT_STRING EXPECT_STRING "}"
#define EXPECT_ARRAY_VALUE EXPECT_VALUE "]"
@@ -248,12 +247,12 @@ escchr:
JSON_INVALID(); /* unbalanced nodes */
nodes[--depth].index++;
- if (!depth)
- expect = EXPECT_NOTHING;
- else
- expect = EXPECT_END;
+ expect = EXPECT_END;
break;
case ',':
+ if (!depth)
+ JSON_INVALID(); /* unbalanced nodes */
+
nodes[depth - 1].index++;
if (nodes[depth - 1].type == TYPE_OBJECT) {
iskey = 1;