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