From 31a353b57152e7b44254853520a06568a4a91dce Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 25 Jan 2022 18:15:46 +0100 Subject: jplist: Make sure the jsmn parser tokens are initialized properly --- src/jplist.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/jplist.c b/src/jplist.c index 3d3cad2..cb29742 100644 --- a/src/jplist.c +++ b/src/jplist.c @@ -657,6 +657,7 @@ PLIST_API int plist_from_json(const char *json, uint32_t length, plist_t * plist jsmn_parser parser; jsmn_init(&parser); int maxtoks = 256; + int curtoks = 0; int r = 0; jsmntok_t *tokens = NULL; @@ -666,14 +667,16 @@ PLIST_API int plist_from_json(const char *json, uint32_t length, plist_t * plist PLIST_JSON_ERR("%s: Out of memory\n", __func__); return PLIST_ERR_NO_MEM; } - tokens = newtokens; + memset((unsigned char*)newtokens + sizeof(jsmntok_t)*curtoks, '\0', sizeof(jsmntok_t)*(maxtoks-curtoks)); + tokens = newtokens; + curtoks = maxtoks; r = jsmn_parse(&parser, json, length, tokens, maxtoks); if (r == JSMN_ERROR_NOMEM) { maxtoks+=16; continue; - } - } while (0); + } + } while (r == JSMN_ERROR_NOMEM); switch(r) { case JSMN_ERROR_NOMEM: -- cgit v1.1-32-gdbae