|
|
9ae3a8 |
From 38d4fe12ad2e3bc18842201f437c480120eace2b Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Date: Wed, 27 Jul 2016 07:35:02 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 04/16] check-qjson: Add test for JSON nesting depth limit
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1469604913-12442-6-git-send-email-armbru@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 71481
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 04/15] check-qjson: Add test for JSON nesting depth limit
|
|
|
9ae3a8 |
Bugzilla: 1276036
|
|
|
9ae3a8 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This would have prevented the regression mentioned in the previous
|
|
|
9ae3a8 |
commit.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
Message-Id: <1448486613-17634-4-git-send-email-armbru@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit f0ae0304c7a41a42b7d4a6cde450da938d3c2cc7)
|
|
|
9ae3a8 |
Signed-off-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
tests/check-qjson.c | 25 +++++++++++++++++++++++++
|
|
|
9ae3a8 |
1 file changed, 25 insertions(+)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
|
|
|
9ae3a8 |
index 4e74548..c5dd74d 100644
|
|
|
9ae3a8 |
--- a/tests/check-qjson.c
|
|
|
9ae3a8 |
+++ b/tests/check-qjson.c
|
|
|
9ae3a8 |
@@ -1465,6 +1465,30 @@ static void unterminated_literal(void)
|
|
|
9ae3a8 |
g_assert(obj == NULL);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+static char *make_nest(char *buf, size_t cnt)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ memset(buf, '[', cnt - 1);
|
|
|
9ae3a8 |
+ buf[cnt - 1] = '{';
|
|
|
9ae3a8 |
+ buf[cnt] = '}';
|
|
|
9ae3a8 |
+ memset(buf + cnt + 1, ']', cnt - 1);
|
|
|
9ae3a8 |
+ buf[2 * cnt] = 0;
|
|
|
9ae3a8 |
+ return buf;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static void limits_nesting(void)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ enum { max_nesting = 1024 }; /* see qobject/json-streamer.c */
|
|
|
9ae3a8 |
+ char buf[2 * (max_nesting + 1) + 1];
|
|
|
9ae3a8 |
+ QObject *obj;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ obj = qobject_from_json(make_nest(buf, max_nesting));
|
|
|
9ae3a8 |
+ g_assert(obj != NULL);
|
|
|
9ae3a8 |
+ qobject_decref(obj);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ obj = qobject_from_json(make_nest(buf, max_nesting + 1));
|
|
|
9ae3a8 |
+ g_assert(obj == NULL);
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
int main(int argc, char **argv)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
g_test_init(&argc, &argv, NULL);
|
|
|
9ae3a8 |
@@ -1500,6 +1524,7 @@ int main(int argc, char **argv)
|
|
|
9ae3a8 |
g_test_add_func("/errors/invalid_array_comma", invalid_array_comma);
|
|
|
9ae3a8 |
g_test_add_func("/errors/invalid_dict_comma", invalid_dict_comma);
|
|
|
9ae3a8 |
g_test_add_func("/errors/unterminated/literal", unterminated_literal);
|
|
|
9ae3a8 |
+ g_test_add_func("/errors/limits/nesting", limits_nesting);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
return g_test_run();
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|