3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-21 22:09:23 +01:00

unit: add larger object test

This tests the previous JSON bug fix removing % sizeof(jsmntok_t)
Objects with more than 10 (sizeof(jsmntok_t)) would not parse
correctly.
This commit is contained in:
James Prestwood 2021-12-10 16:21:37 -08:00 committed by Denis Kenzior
parent 1c1b63aae7
commit 385dd2d469

View File

@ -219,6 +219,35 @@ static void test_json_out_of_order(const void *data)
json_contents_free(c); json_contents_free(c);
} }
/*
* Tests that the token bounds checking works.
*/
static void test_json_larger_object(const void *data)
{
char json[] = "{\"test1\":\"tester1\","
"\"test2\":\"tester2\","
"\"test3\":\"tester3\","
"\"test4\":\"tester4\","
"\"test5\":\"tester5\","
"\"test6\":\"tester6\","
"\"test7\":\"tester7\","
"\"test8\":\"tester8\","
"\"test9\":\"tester9\","
"\"test10\":\"tester10\","
"\"test11\":\"tester11\","
"\"test12\":\"tester12\","
"\"test13\":\"tester13\"}";
struct json_iter iter;
struct json_contents *c = json_contents_new(json, strlen(json));
json_iter_init(&iter, c);
assert(json_iter_parse(&iter,
JSON_MANDATORY("test13", JSON_STRING, NULL),
JSON_UNDEFINED));
json_contents_free(c);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
l_test_init(&argc, &argv); l_test_init(&argc, &argv);
@ -229,6 +258,7 @@ int main(int argc, char *argv[])
l_test_add("json unsupported types", test_json_unsupported_types, NULL); l_test_add("json unsupported types", test_json_unsupported_types, NULL);
l_test_add("json empty objects", test_json_empty_objects, NULL); l_test_add("json empty objects", test_json_empty_objects, NULL);
l_test_add("json parse out of order", test_json_out_of_order, NULL); l_test_add("json parse out of order", test_json_out_of_order, NULL);
l_test_add("json larger object", test_json_larger_object, NULL);
return l_test_run(); return l_test_run();
} }