diff options
author | oxpa <iippolitov@gmail.com> | 2024-09-17 14:21:10 +0100 |
---|---|---|
committer | oxpa <iippolitov@gmail.com> | 2024-09-17 14:21:10 +0100 |
commit | 2417826d8bebf921ee1be102ef8ce702f0683d66 (patch) | |
tree | 76d29a1705415ed7368870826dbb2f04942ee794 /fuzzing/nxt_json_fuzz.c | |
parent | 0e79d961bb1ea68674961da1703ffedb1ddf6e43 (diff) | |
parent | 24ed91f40634372d99f67f0e4e3c2ac0abde81bd (diff) | |
download | unit-2417826d8bebf921ee1be102ef8ce702f0683d66.tar.gz unit-2417826d8bebf921ee1be102ef8ce702f0683d66.tar.bz2 |
Merge tag '1.33.0' into packaging.
Unit 1.33.0 release.
Diffstat (limited to 'fuzzing/nxt_json_fuzz.c')
-rw-r--r-- | fuzzing/nxt_json_fuzz.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/fuzzing/nxt_json_fuzz.c b/fuzzing/nxt_json_fuzz.c new file mode 100644 index 00000000..fa222988 --- /dev/null +++ b/fuzzing/nxt_json_fuzz.c @@ -0,0 +1,97 @@ +/* + * Copyright (C) NGINX, Inc. + */ + +#include <nxt_main.h> +#include <nxt_conf.h> +#include <nxt_router.h> + +#define KMININPUTLENGTH 2 +#define KMAXINPUTLENGTH 1024 + + +extern int LLVMFuzzerInitialize(int *argc, char ***argv); +extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); + + +extern char **environ; + + +int +LLVMFuzzerInitialize(int *argc, char ***argv) +{ + if (nxt_lib_start("fuzzing", NULL, &environ) != NXT_OK) { + return NXT_ERROR; + } + + return 0; +} + + +int +LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + nxt_mp_t *mp; + nxt_str_t input; + nxt_thread_t *thr; + nxt_runtime_t *rt; + nxt_conf_value_t *conf; + nxt_conf_validation_t vldt; + nxt_conf_json_pretty_t pretty; + + if (size < KMININPUTLENGTH || size > KMAXINPUTLENGTH) { + return 0; + } + + thr = nxt_thread(); + + mp = nxt_mp_create(1024, 128, 256, 32); + if (mp == NULL) { + return 0; + } + + rt = nxt_mp_zget(mp, sizeof(nxt_runtime_t)); + if (rt == NULL) { + goto failed; + } + + rt->languages = nxt_array_create(mp, 1, sizeof(nxt_app_lang_module_t)); + if (rt->languages == NULL) { + goto failed; + } + + input.start = (u_char *)data; + input.length = size; + + thr->runtime = rt; + rt->mem_pool = mp; + + nxt_memzero(&pretty, sizeof(nxt_conf_json_pretty_t)); + nxt_memzero(&vldt, sizeof(nxt_conf_validation_t)); + + conf = nxt_conf_json_parse_str(mp, &input); + if (conf == NULL) { + goto failed; + } + + nxt_conf_json_length(conf, NULL); + nxt_conf_json_length(conf, &pretty); + + vldt.pool = nxt_mp_create(1024, 128, 256, 32); + if (vldt.pool == NULL) { + goto failed; + } + + vldt.conf = conf; + vldt.conf_pool = mp; + vldt.ver = NXT_VERNUM; + + nxt_conf_validate(&vldt); + nxt_mp_destroy(vldt.pool); + +failed: + + nxt_mp_destroy(mp); + + return 0; +} |