cJSON

mirror of Dave's cJSON
git clone git://git.thc420.xyz/cJSON
Log | Files | Refs | README | LICENSE

commit 08d2bc766a82cd75764d036f9efef444590d1cf9
parent 465352fb9987d3a4713963c61f6dc0b566abf1cd
Author: Max Bruckner <max@maxbruckner.de>
Date:   Thu, 16 May 2019 20:01:02 +0200

Fix infinite loop in cJSON_Minify

Diffstat:
McJSON.c | 2++
Mtests/minify_tests.c | 7+++++++
2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/cJSON.c b/cJSON.c @@ -2717,6 +2717,8 @@ CJSON_PUBLIC(void) cJSON_Minify(char *json) else if (json[1] == '*') { skip_multiline_comment(&json); + } else { + json++; } break; diff --git a/tests/minify_tests.c b/tests/minify_tests.c @@ -152,6 +152,12 @@ static void cjson_minify_should_minify_json(void) { free(buffer); } +static void cjson_minify_should_not_loop_infinitely(void) { + char string[] = { '8', ' ', '/', ' ', '5', '\n', '\0' }; + /* this should not be an infinite loop */ + cJSON_Minify(string); +} + int CJSON_CDECL main(void) { UNITY_BEGIN(); @@ -162,6 +168,7 @@ int CJSON_CDECL main(void) RUN_TEST(cjson_minify_should_remove_multiline_comments); RUN_TEST(cjson_minify_should_remove_spaces); RUN_TEST(cjson_minify_should_not_modify_strings); + RUN_TEST(cjson_minify_should_not_loop_infinitely); return UNITY_END(); }