Skip to content

Commit

Permalink
Fix infinite loop in cJSON_Minify
Browse files Browse the repository at this point in the history
  • Loading branch information
FSMaxB committed May 16, 2019
1 parent 465352f commit 08d2bc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,8 @@ CJSON_PUBLIC(void) cJSON_Minify(char *json)
else if (json[1] == '*')
{
skip_multiline_comment(&json);
} else {
json++;
}
break;

Expand Down
7 changes: 7 additions & 0 deletions tests/minify_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}

0 comments on commit 08d2bc7

Please sign in to comment.