Skip to content

Commit

Permalink
fuzzing: beautified and updated JSON target
Browse files Browse the repository at this point in the history
Added 'nxt_conf_json_length' check for extra hit coverage.

Fixes: a93d878 ("fuzzing: add fuzzing targets")
  • Loading branch information
pkillarjun committed Jul 27, 2024
1 parent 8f969f2 commit 3931ef1
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions fuzzing/nxt_json_fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,63 +31,78 @@ LLVMFuzzerInitialize(int *argc, char ***argv)
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_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;
}

input.start = (u_char *)data;
input.length = size;

nxt_memzero(&pretty, sizeof(nxt_conf_json_pretty_t));
nxt_memzero(&vldt, sizeof(nxt_conf_validation_t));


/*
* Create memory pool and validation pool.
* Initialize 'nxt_runtime_t'.
*/
thr = nxt_thread();

mp = nxt_mp_create(1024, 128, 256, 32);
if (mp == NULL) {
return 0;
}

vldt.pool = nxt_mp_create(1024, 128, 256, 32);
if (vldt.pool == NULL) {
nxt_mp_destroy(mp);
return 0;
}

rt = nxt_mp_zget(mp, sizeof(nxt_runtime_t));
if (rt == NULL) {
goto failed;
}

thr->runtime = rt;
rt->mem_pool = mp;

input.start = (u_char *)data;
input.length = size;

conf = nxt_conf_json_parse_str(mp, &input);
if (conf == NULL) {
rt->languages = nxt_array_create(mp, 1, sizeof(nxt_app_lang_module_t));
if (rt->languages == NULL) {
goto failed;
}

nxt_memzero(&vldt, sizeof(nxt_conf_validation_t));

vldt.pool = nxt_mp_create(1024, 128, 256, 32);
if (vldt.pool == NULL) {
goto failed;
}
rt->mem_pool = mp;
thr->runtime = rt;

vldt.conf = conf;
vldt.conf_pool = mp;
vldt.ver = NXT_VERNUM;

rt->languages = nxt_array_create(mp, 1, sizeof(nxt_app_lang_module_t));
if (rt->languages == NULL) {

/*
* Parse json and validate conf.
*/
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.conf = conf;
nxt_conf_validate(&vldt);

nxt_mp_destroy(vldt.pool);

failed:

nxt_mp_destroy(mp);
nxt_mp_destroy(vldt.pool);

return 0;
}

0 comments on commit 3931ef1

Please sign in to comment.