summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArun Raghavan <arun@arunraghavan.net>2016-06-01 17:18:33 +0530
committerArun Raghavan <arun@arunraghavan.net>2016-06-22 21:04:47 +0530
commit708b4aac91ce8220480df6a34ccb491be2b8d490 (patch)
treea94059344fc9ad012faf1559a7556c4477ae3511 /src
parentc692ec3afdba560398fd9a6871cddcca6d5c9cc5 (diff)
json: Correctly handle bad strings with missing closing quotes
Also add a test for this case. Signed-off-by: Arun Raghavan <arun@arunraghavan.net>
Diffstat (limited to 'src')
-rw-r--r--src/pulse/json.c2
-rw-r--r--src/tests/json-test.c13
2 files changed, 14 insertions, 1 deletions
diff --git a/src/pulse/json.c b/src/pulse/json.c
index 8484bba82..6297902cb 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 only accept ASCII printable characters. */
if (*str < 0x20 || *str > 0x7E) {
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);