main: fix spurious premature parse aborts in array mode master
authorJo-Philipp Wich <jo@mein.io>
Tue, 23 Jan 2024 07:55:43 +0000 (08:55 +0100)
committerJo-Philipp Wich <jo@mein.io>
Tue, 23 Jan 2024 07:55:43 +0000 (08:55 +0100)
When reading newline separated JSON (array mode), continue parsing even
if the JSON tokener signals success, as another object might follow.

Fixes: FS#3683
Fixes: openwrt#8703
Fixes: openwrt#11649
Fixes: openwrt#12344
Fixes: 8614470 ("main: implement array mode")
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
main.c

diff --git a/main.c b/main.c
index 5041d10de8343915ca85136c569c0d66c34ddae2..a0c7b0390c41997d2b600295a202a22a1411cd5c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -146,10 +146,8 @@ parse_json(FILE *fd, const char *source, const char **error, bool array_mode)
                {
                        obj = parse_json_chunk(tok, array, buf, len, &err);
 
-                       if (err == json_tokener_success && !array)
-                               break;
-
-                       if (err != json_tokener_continue)
+                       if ((err == json_tokener_success && array_mode == false) ||
+                           (err != json_tokener_continue && err != json_tokener_success))
                                break;
                }
        }