diff options
Diffstat (limited to 'src/fuzz/fuzz-bootspec.c')
-rw-r--r-- | src/fuzz/fuzz-bootspec.c | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/src/fuzz/fuzz-bootspec.c b/src/fuzz/fuzz-bootspec.c index 0c61cbe39e..e49acafe31 100644 --- a/src/fuzz/fuzz-bootspec.c +++ b/src/fuzz/fuzz-bootspec.c @@ -2,17 +2,20 @@ #include <string.h> +#include "sd-json.h" + #include "bootspec.h" #include "env-util.h" #include "escape.h" -#include "fuzz.h" #include "fd-util.h" -#include "json.h" +#include "fuzz.h" +#include "json-util.h" +#include "strv.h" -static int json_dispatch_config(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +static int json_dispatch_config(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { BootConfig *config = ASSERT_PTR(userdata); - const char *s = json_variant_string(variant); + const char *s = sd_json_variant_string(variant); if (!s) return -EINVAL; @@ -23,29 +26,29 @@ static int json_dispatch_config(const char *name, JsonVariant *variant, JsonDisp return 0; } -static int json_dispatch_entries(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +static int json_dispatch_entries(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { BootConfig *config = ASSERT_PTR(userdata); - JsonVariant *entry; + sd_json_variant *entry; JSON_VARIANT_ARRAY_FOREACH(entry, variant) { - if (!json_variant_is_array(entry) || - json_variant_elements(entry) < 1) + if (!sd_json_variant_is_array(entry) || + sd_json_variant_elements(entry) < 1) return -EINVAL; - JsonVariant *v; + sd_json_variant *v; const char *id = NULL, *raw = NULL; _cleanup_free_ char *data = NULL; ssize_t len = -ENODATA; - v = json_variant_by_index(entry, 0); + v = sd_json_variant_by_index(entry, 0); if (v) - id = json_variant_string(v); + id = sd_json_variant_string(v); if (!id) continue; - v = json_variant_by_index(entry, 1); + v = sd_json_variant_by_index(entry, 1); if (v) - raw = json_variant_string(v); + raw = sd_json_variant_string(v); if (raw) len = cunescape(raw, UNESCAPE_RELAX | UNESCAPE_ACCEPT_NUL, &data); if (len >= 0) { @@ -59,12 +62,12 @@ static int json_dispatch_entries(const char *name, JsonVariant *variant, JsonDis return 0; } -static int json_dispatch_loader(const char *name, JsonVariant *variant, JsonDispatchFlags flags, void *userdata) { +static int json_dispatch_loader(const char *name, sd_json_variant *variant, sd_json_dispatch_flags_t flags, void *userdata) { BootConfig *config = ASSERT_PTR(userdata); _cleanup_strv_free_ char **entries = NULL; int r; - r = json_dispatch_strv(name, variant, flags, &entries); + r = sd_json_dispatch_strv(name, variant, flags, &entries); if (r < 0) return r; @@ -72,10 +75,10 @@ static int json_dispatch_loader(const char *name, JsonVariant *variant, JsonDisp return 0; } -static const JsonDispatch data_dispatch[] = { - { "config", JSON_VARIANT_STRING, json_dispatch_config, 0, 0 }, - { "entries", JSON_VARIANT_ARRAY, json_dispatch_entries, 0, 0 }, - { "loader", JSON_VARIANT_ARRAY, json_dispatch_loader, 0, 0 }, +static const sd_json_dispatch_field data_dispatch[] = { + { "config", SD_JSON_VARIANT_STRING, json_dispatch_config, 0, 0 }, + { "entries", SD_JSON_VARIANT_ARRAY, json_dispatch_entries, 0, 0 }, + { "loader", SD_JSON_VARIANT_ARRAY, json_dispatch_loader, 0, 0 }, {} }; @@ -91,12 +94,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { assert_se(datadup = memdup_suffix0(data, size)); - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; - r = json_parse(datadup, 0, &v, NULL, NULL); + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; + r = sd_json_parse(datadup, 0, &v, NULL, NULL); if (r < 0) return 0; - r = json_dispatch(v, data_dispatch, 0, &config); + r = sd_json_dispatch(v, data_dispatch, 0, &config); if (r < 0) return 0; @@ -113,8 +116,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { assert_se(freopen("/dev/null", "w", stdout)); } - (void) show_boot_entries(&config, JSON_FORMAT_OFF); - (void) show_boot_entries(&config, JSON_FORMAT_PRETTY); + (void) show_boot_entries(&config, SD_JSON_FORMAT_OFF); + (void) show_boot_entries(&config, SD_JSON_FORMAT_PRETTY); if (orig_stdout_fd >= 0) assert_se(freopen(FORMAT_PROC_FD_PATH(orig_stdout_fd), "w", stdout)); |