Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzzing: cifuzz workflow, fix oss-fuzz issues, updated dir name #1327

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/cifuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CIFuzz
on:
pull_request:
paths:
- 'src/**'
- 'fuzzing/**'
- '.github/workflows/cifuzz.yml'

permissions: {}
jobs:
Fuzzing:
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- name: Build Fuzzers
id: build
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'unit'
language: c
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'unit'
language: c
fuzz-seconds: 300
output-sarif: true
- name: Upload Crash
uses: actions/upload-artifact@v3
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
path: ./out/artifacts
- name: Upload Sarif
if: always() && steps.build.outcome == 'success'
uses: github/codeql-action/upload-sarif@v2
pkillarjun marked this conversation as resolved.
Show resolved Hide resolved
with:
# Path to SARIF file relative to the root of the repository
sarif_file: cifuzz-sarif/results.sarif
checkout_path: cifuzz-sarif
10 changes: 5 additions & 5 deletions fuzzing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ $ mkdir -p build/fuzz_http_h1p_seed
$ mkdir -p build/fuzz_http_h1p_peer_seed
$ mkdir -p build/fuzz_json_seed

$ ./build/fuzz_basic build/fuzz_basic_seed src/fuzz/fuzz_basic_seed_corpus
$ ./build/fuzz_http_controller build/fuzz_http_controller_seed src/fuzz/fuzz_http_controller_seed_corpus
$ ./build/fuzz_http_h1p build/fuzz_http_h1p_seed src/fuzz/fuzz_http_h1p_seed_corpus
$ ./build/fuzz_http_h1p_peer build/fuzz_http_h1p_peer_seed src/fuzz/fuzz_http_h1p_peer_seed_corpus
$ ./build/fuzz_json build/fuzz_json_seed src/fuzz/fuzz_json_seed_corpus
$ ./build/fuzz_basic build/fuzz_basic_seed fuzzing/fuzz_basic_seed_corpus
$ ./build/fuzz_http_controller build/fuzz_http_controller_seed fuzzing/fuzz_http_seed_corpus
$ ./build/fuzz_http_h1p build/fuzz_http_h1p_seed fuzzing/fuzz_http_seed_corpus
$ ./build/fuzz_http_h1p_peer build/fuzz_http_h1p_peer_seed fuzzing/fuzz_http_seed_corpus
$ ./build/fuzz_json build/fuzz_json_seed fuzzing/fuzz_json_seed_corpus
```

Here is more information about [LibFuzzer](https://llvm.org/docs/LibFuzzer.html).
Expand Down
2 changes: 1 addition & 1 deletion fuzzing/build-fuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ mkdir -p build/fuzz_http_h1p_peer_seed
mkdir -p build/fuzz_json_seed

echo ""
echo "Run: ./build/\${fuzzer} build/\${fuzzer}_seed src/fuzz/\${fuzzer}_seed_corpus"
echo "Run: ./build/\${fuzzer} build/\${fuzzer}_seed fuzzing/\${fuzzer}_seed_corpus"
echo ""
8 changes: 8 additions & 0 deletions fuzzing/nxt_http_controller_fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
goto failed;
}

r_controller->conn = nxt_mp_zget(mp, sizeof(nxt_conn_t));
if (r_controller->conn == NULL) {
goto failed;
}

nxt_main_log.level = NXT_LOG_ALERT;
r_controller->conn->log = nxt_main_log;

nxt_http_fields_process(rp.fields, &nxt_controller_fields_hash,
r_controller);

Expand Down
2 changes: 2 additions & 0 deletions fuzzing/nxt_http_h1p_fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
goto failed;
}

r_h1p->mem_pool = mp;

nxt_http_fields_process(rp.fields, &nxt_h1p_fields_hash, r_h1p);

failed:
Expand Down
19 changes: 18 additions & 1 deletion fuzzing/nxt_json_fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <nxt_main.h>
#include <nxt_conf.h>

#include <nxt_router.h>

#define KMININPUTLENGTH 2
#define KMAXINPUTLENGTH 1024
Expand Down Expand Up @@ -33,18 +33,30 @@ 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;

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;
}

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

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

Expand All @@ -64,6 +76,11 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
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) {
goto failed;
}

nxt_conf_validate(&vldt);

nxt_mp_destroy(vldt.pool);
Expand Down
Loading