summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2022-01-25 18:15:46 +0100
committerGravatar Nikias Bassen2022-01-25 18:15:46 +0100
commit31a353b57152e7b44254853520a06568a4a91dce (patch)
tree4fd274a52941455d5984592896bf95a1e76b0a18
parentf3c65feb0e1f4e177a75ba936d0730f7c3f4b076 (diff)
downloadlibplist-31a353b57152e7b44254853520a06568a4a91dce.tar.gz
libplist-31a353b57152e7b44254853520a06568a4a91dce.tar.bz2
jplist: Make sure the jsmn parser tokens are initialized properly
-rw-r--r--src/jplist.c9
1 files 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
657 jsmn_parser parser; 657 jsmn_parser parser;
658 jsmn_init(&parser); 658 jsmn_init(&parser);
659 int maxtoks = 256; 659 int maxtoks = 256;
660 int curtoks = 0;
660 int r = 0; 661 int r = 0;
661 jsmntok_t *tokens = NULL; 662 jsmntok_t *tokens = NULL;
662 663
@@ -666,14 +667,16 @@ PLIST_API int plist_from_json(const char *json, uint32_t length, plist_t * plist
666 PLIST_JSON_ERR("%s: Out of memory\n", __func__); 667 PLIST_JSON_ERR("%s: Out of memory\n", __func__);
667 return PLIST_ERR_NO_MEM; 668 return PLIST_ERR_NO_MEM;
668 } 669 }
669 tokens = newtokens; 670 memset((unsigned char*)newtokens + sizeof(jsmntok_t)*curtoks, '\0', sizeof(jsmntok_t)*(maxtoks-curtoks));
671 tokens = newtokens;
672 curtoks = maxtoks;
670 673
671 r = jsmn_parse(&parser, json, length, tokens, maxtoks); 674 r = jsmn_parse(&parser, json, length, tokens, maxtoks);
672 if (r == JSMN_ERROR_NOMEM) { 675 if (r == JSMN_ERROR_NOMEM) {
673 maxtoks+=16; 676 maxtoks+=16;
674 continue; 677 continue;
675 } 678 }
676 } while (0); 679 } while (r == JSMN_ERROR_NOMEM);
677 680
678 switch(r) { 681 switch(r) {
679 case JSMN_ERROR_NOMEM: 682 case JSMN_ERROR_NOMEM: