From cde88418f304c4b62d83f142b9bfd7818aa34613 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 7 Sep 2009 12:38:56 +0000 Subject: Enable JSON parser to recognize a type mismatch. --- json.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'json.c') diff --git a/json.c b/json.c index 8262dbcb..b0bdd7fb 100644 --- a/json.c +++ b/json.c @@ -98,7 +98,7 @@ static int json_internal_read_object(const char *cp, const struct json_attr_t *a #ifdef JSONDEBUG char *statenames[] = { "init", "await_attr", "in_attr", "await_value", - "in_val_string", "in_val_token", "post_val" + "in_val_string", "in_escape", "in_val_token", "post_val" }; #endif /* JSONDEBUG */ char attrbuf[JSON_ATTR_MAX+1], *pattr = NULL; @@ -219,6 +219,10 @@ static int json_internal_read_object(const char *cp, const struct json_attr_t *a json_debug_trace(("Array element was specified, but no [.\n")); return JSON_ERR_NOBRAK; } else if (*cp == '"') { + if (cursor->type != string) { + json_debug_trace(("Saw string quote when expecting non-string.\n")); + return JSON_ERR_QNONSTRING; + } state = in_val_string; pval = valbuf; } else { @@ -464,6 +468,7 @@ const char *json_error_string(int err) "check attribute not matched", "can't support strings in parallel arrays", "invalid enumerated value", + "saw string quote when expecting nonstring", "other data conversion error", }; -- cgit v1.2.1