[pulseaudio-discuss] [PATCH v2 3/9] json: Correctly handle bad strings with missing closing quotes

Arun Raghavan arun at arunraghavan.net
Wed Jun 1 11:48:33 UTC 2016


Also add a test for this case.

Signed-off-by: Arun Raghavan <arun at arunraghavan.net>
---
 src/pulse/json.c      |  2 +-
 src/tests/json-test.c | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/pulse/json.c b/src/pulse/json.c
index 6cb28b9..4d5500f 100644
--- a/src/pulse/json.c
+++ b/src/pulse/json.c
@@ -122,7 +122,7 @@ static const char* parse_string(const char *str, pa_json_object *obj) {
 
     str++; /* Consume leading '"' */
 
-    while (*str != '"') {
+    while (*str && *str != '"') {
         if (*str != '\\') {
             /* We don't accept non-ASCII, non-control characters */
             if (*str < 0x20) {
diff --git a/src/tests/json-test.c b/src/tests/json-test.c
index 2e1ca6b..7d273d7 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);
-- 
2.5.5



More information about the pulseaudio-discuss mailing list