From 708b4aac91ce8220480df6a34ccb491be2b8d490 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Wed, 1 Jun 2016 17:18:33 +0530 Subject: json: Correctly handle bad strings with missing closing quotes Also add a test for this case. Signed-off-by: Arun Raghavan --- src/tests/json-test.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/tests') diff --git a/src/tests/json-test.c b/src/tests/json-test.c index 2e1ca6b92..7d273d70c 100644 --- a/src/tests/json-test.c +++ b/src/tests/json-test.c @@ -216,6 +216,18 @@ START_TEST(array_test) { } END_TEST +START_TEST(bad_test) { + unsigned int i; + const char *bad_parse[] = { + "\"" /* Quote not closed */, + }; + + for (i = 0; i < PA_ELEMENTSOF(bad_parse); i++) { + fail_unless(pa_json_parse(bad_parse[i]) == NULL); + } +} +END_TEST + int main(int argc, char *argv[]) { int failed = 0; Suite *s; @@ -231,6 +243,7 @@ int main(int argc, char *argv[]) { tcase_add_test(tc, bool_test); tcase_add_test(tc, object_test); tcase_add_test(tc, array_test); + tcase_add_test(tc, bad_test); suite_add_tcase(s, tc); sr = srunner_create(s); -- cgit v1.2.3