From 08d2bc766a82cd75764d036f9efef444590d1cf9 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Thu, 16 May 2019 20:01:02 +0200 Subject: [PATCH] Fix infinite loop in cJSON_Minify --- cJSON.c | 2 ++ tests/minify_tests.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/cJSON.c b/cJSON.c index 3a5dc54..f9c2ffa 100644 --- 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 index e39a944..000821d 100644 --- 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(); }