You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.8 KiB
97 lines
3.8 KiB
From 495eb07a2d8aa7f19b775b4508466fecb1b3ce50 Mon Sep 17 00:00:00 2001 |
|
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl> |
|
Date: Mon, 9 May 2022 11:07:06 +0200 |
|
Subject: [PATCH] fuzz-json: also do sorting and normalizing and other easy |
|
calls |
|
|
|
(cherry picked from commit a2c5735dd80e19d2d525f9be322395530096cbe2) |
|
Related: #2087652 |
|
--- |
|
src/fuzz/fuzz-json.c | 75 ++++++++++++++++++++++++++++++++++++++++++++ |
|
1 file changed, 75 insertions(+) |
|
|
|
diff --git a/src/fuzz/fuzz-json.c b/src/fuzz/fuzz-json.c |
|
index 648a6d441d..995a0265ba 100644 |
|
--- a/src/fuzz/fuzz-json.c |
|
+++ b/src/fuzz/fuzz-json.c |
|
@@ -32,5 +32,80 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
|
json_variant_dump(v, 0, g ?: stdout, NULL); |
|
json_variant_dump(v, JSON_FORMAT_PRETTY|JSON_FORMAT_COLOR|JSON_FORMAT_SOURCE, g ?: stdout, NULL); |
|
|
|
+ bool sorted = json_variant_is_sorted(v); |
|
+ log_debug("json_variant_is_sorted: %s", yes_no(sorted)); |
|
+ |
|
+ r = json_variant_sort(&v); |
|
+ log_debug_errno(r, "json_variant_sort: %d/%m", r); |
|
+ |
|
+ sorted = json_variant_is_sorted(v); |
|
+ log_debug("json_variant_is_sorted: %s", yes_no(sorted)); |
|
+ assert_se(r < 0 || sorted); |
|
+ |
|
+ bool normalized = json_variant_is_normalized(v); |
|
+ log_debug("json_variant_is_normalized: %s", yes_no(normalized)); |
|
+ |
|
+ r = json_variant_normalize(&v); |
|
+ log_debug_errno(r, "json_variant_normalize: %d/%m", r); |
|
+ |
|
+ normalized = json_variant_is_normalized(v); |
|
+ log_debug("json_variant_is_normalized: %s", yes_no(normalized)); |
|
+ assert_se(r < 0 || normalized); |
|
+ |
|
+ double real = json_variant_real(v); |
|
+ log_debug("json_variant_real: %lf", real); |
|
+ |
|
+ bool negative = json_variant_is_negative(v); |
|
+ log_debug("json_variant_is_negative: %s", yes_no(negative)); |
|
+ |
|
+ bool blank = json_variant_is_blank_object(v); |
|
+ log_debug("json_variant_is_blank_object: %s", yes_no(blank)); |
|
+ |
|
+ blank = json_variant_is_blank_array(v); |
|
+ log_debug("json_variant_is_blank_array: %s", yes_no(blank)); |
|
+ |
|
+ size_t elements = json_variant_elements(v); |
|
+ log_debug("json_variant_elements: %zu", elements); |
|
+ |
|
+ for (size_t i = 0; i <= elements + 2; i++) |
|
+ (void) json_variant_by_index(v, i); |
|
+ |
|
+ assert_se(json_variant_equal(v, v)); |
|
+ assert_se(!json_variant_equal(v, NULL)); |
|
+ assert_se(!json_variant_equal(NULL, v)); |
|
+ |
|
+ bool sensitive = json_variant_is_sensitive(v); |
|
+ log_debug("json_variant_is_sensitive: %s", yes_no(sensitive)); |
|
+ |
|
+ json_variant_sensitive(v); |
|
+ |
|
+ sensitive = json_variant_is_sensitive(v); |
|
+ log_debug("json_variant_is_sensitive: %s", yes_no(sensitive)); |
|
+ |
|
+ const char *source; |
|
+ unsigned line, column; |
|
+ assert_se(json_variant_get_source(v, &source, &line, &column) == 0); |
|
+ log_debug("json_variant_get_source: %s:%u:%u", source ?: "-", line, column); |
|
+ |
|
+ r = json_variant_set_field_string(&v, "a", "string-a"); |
|
+ log_debug_errno(r, "json_set_field_string: %d/%m", r); |
|
+ |
|
+ r = json_variant_set_field_integer(&v, "b", -12345); |
|
+ log_debug_errno(r, "json_set_field_integer: %d/%m", r); |
|
+ |
|
+ r = json_variant_set_field_unsigned(&v, "c", 12345); |
|
+ log_debug_errno(r, "json_set_field_unsigned: %d/%m", r); |
|
+ |
|
+ r = json_variant_set_field_boolean(&v, "d", false); |
|
+ log_debug_errno(r, "json_set_field_boolean: %d/%m", r); |
|
+ |
|
+ r = json_variant_set_field_strv(&v, "e", STRV_MAKE("e-1", "e-2", "e-3")); |
|
+ log_debug_errno(r, "json_set_field_strv: %d/%m", r); |
|
+ |
|
+ r = json_variant_filter(&v, STRV_MAKE("a", "b", "c", "d", "e")); |
|
+ log_debug_errno(r, "json_variant_filter: %d/%m", r); |
|
+ |
|
+ // TODO: json_variant_merge(&v, …); |
|
+ // TODO: json_variant_append_array(&v, …); |
|
return 0; |
|
}
|
|
|