[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 11/18] qjson: report error on unterminated string
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v2 11/18] qjson: report error on unterminated string |
Date: |
Thu, 19 Jul 2018 20:41:04 +0200 |
An unterminated string will make parser emit an error (tokens ==
NULL). Let's report it.
Signed-off-by: Marc-André Lureau <address@hidden>
---
qobject/qjson.c | 3 +++
tests/check-qjson.c | 6 +++---
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/qobject/qjson.c b/qobject/qjson.c
index 8a9d116150..01218c9ad6 100644
--- a/qobject/qjson.c
+++ b/qobject/qjson.c
@@ -37,6 +37,9 @@ static void parse_json(JSONMessageParser *parser, GQueue
*tokens)
{
JSONParsingState *s = container_of(parser, JSONParsingState, parser);
+ if (!tokens && !s->err) {
+ error_setg(&s->err, QERR_JSON_PARSING);
+ }
if (s->result || s->err) {
if (s->result) {
qobject_unref(s->result);
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 7d3547e0cc..e602abda11 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -1315,7 +1315,7 @@ static void unterminated_string(void)
{
Error *err = NULL;
QObject *obj = qobject_from_json("\"abc", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
@@ -1323,7 +1323,7 @@ static void unterminated_sq_string(void)
{
Error *err = NULL;
QObject *obj = qobject_from_json("'abc", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
@@ -1331,7 +1331,7 @@ static void unterminated_escape(void)
{
Error *err = NULL;
QObject *obj = qobject_from_json("\"abc\\\"", &err);
- g_assert(!err); /* BUG */
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
--
2.18.0.129.ge3331758f1
- [Qemu-devel] [PATCH v2 00/18] monitor: various code simplification and fixes, Marc-André Lureau, 2018/07/19
- [Qemu-devel] [PATCH v2 03/18] qmp: constify qmp_is_oob(), Marc-André Lureau, 2018/07/19
- [Qemu-devel] [PATCH v2 01/18] tests: change /0.15/* tests to /qmp/*, Marc-André Lureau, 2018/07/19
- [Qemu-devel] [PATCH v2 02/18] monitor: consitify qmp_send_response() QDict argument, Marc-André Lureau, 2018/07/19
- [Qemu-devel] [PATCH v2 04/18] Revert "qmp: isolate responses into io thread", Marc-André Lureau, 2018/07/19
- [Qemu-devel] [PATCH v2 05/18] monitor: no need to save need_resume, Marc-André Lureau, 2018/07/19
- [Qemu-devel] [PATCH v2 11/18] qjson: report error on unterminated string,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v2 08/18] json-parser: simplify and avoid JSONParserContext allocation, Marc-André Lureau, 2018/07/19
- [Qemu-devel] [PATCH v2 10/18] qjson: report an error if there are multiple results, Marc-André Lureau, 2018/07/19
- [Qemu-devel] [PATCH v2 09/18] json-parser: further simplify freeing JSONParserContext, Marc-André Lureau, 2018/07/19
- [Qemu-devel] [PATCH v2 06/18] qga: process_event() simplification and leak fix, Marc-André Lureau, 2018/07/19