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

Add cflite and document normalize path #280

Merged
merged 3 commits into from
Sep 16, 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
6 changes: 6 additions & 0 deletions .clusterfuzzlite/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM gcr.io/oss-fuzz-base/base-builder
RUN apt-get update && apt-get install -y make autoconf automake libtool
COPY . $SRC/uvwasi
COPY .clusterfuzzlite/build.sh $SRC/build.sh
COPY .clusterfuzzlite/*.c $SRC/
WORKDIR uvwasi
11 changes: 11 additions & 0 deletions .clusterfuzzlite/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Disable building of shared library
#sed -i 's/add\_library(uvwasi SHARED/# /g' CMakeLists.txt
mkdir build
cd build
cmake ../
make uvwasi_a

$CC $CFLAGS $LIB_FUZZING_ENGINE ../.clusterfuzzlite/fuzz_normalize_path.c \
-o $OUT/fuzz_normalize_path \
./libuvwasi_a.a _deps/libuv-build/libuv_a.a \
-I$SRC/uvwasi/include -I$PWD/_deps/libuv-src/include/
25 changes: 25 additions & 0 deletions .clusterfuzzlite/fuzz_normalize_path.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "../src/path_resolver.h"

#define BUFFER_SIZE 128

char normalized_buffer[BUFFER_SIZE+1];

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
char *new_str = (char *)malloc(size + 1);
if (new_str == NULL) {
return 0;
}
memcpy(new_str, data, size);
new_str[size] = '\0';

memset(normalized_buffer, 0, BUFFER_SIZE);

uvwasi__normalize_path(new_str, size, normalized_buffer, BUFFER_SIZE);

free(new_str);
return 0;
}
1 change: 1 addition & 0 deletions .clusterfuzzlite/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: c
29 changes: 29 additions & 0 deletions .github/workflows/cflite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ClusterFuzzLite PR fuzzing
on:
workflow_dispatch:
pull_request:
branches: [ main ]
permissions: read-all
jobs:
PR:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sanitizer: [address]
steps:
- name: Build Fuzzers (${{ matrix.sanitizer }})
id: build
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
with:
sanitizer: ${{ matrix.sanitizer }}
language: c
bad-build-check: false
- name: Run Fuzzers (${{ matrix.sanitizer }})
id: run
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
with:
fuzz-seconds: 100
mode: 'code-change'
report-unreproducible-crashes: false
sanitizer: ${{ matrix.sanitizer }}
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2500,6 +2500,26 @@ To do a release complete the following steps:
* Update uvwasi in Node.js or any projects you want to update - there are several
other projects that use uvwasi.

## Running fuzzers locally

We support fuzzing by way of [ClusterFuzzLite](https://google.github.io/clusterfuzzlite/),
which is run automatically against pull requests. You can run these fuzzers
locally with the [OSS-Fuzz](https://github.com/google/oss-fuzz) fuzzing
infrastructure, using the following steps:

```sh
git clone https://github.com/google/oss-fuzz
git clone https://github.com/nodejs/uvwasi
cd uvwasi

# Build the fuzzers in .clusterfuzzlite
python3 ../oss-fuzz/infra/helper.py build_fuzzers --external $PWD

# Run the fuzzer for 10 seconds
python3 ../oss-fuzz/infra/helper.py run_fuzzer --external $PWD fuzz_normalize_path -- -max_total_time=10
```


[WASI]: https://github.com/WebAssembly/WASI
[libuv]: https://github.com/libuv/libuv
[preview 1]: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md
7 changes: 6 additions & 1 deletion src/path_resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ uvwasi_errno_t uvwasi__normalize_path(const char* path,
uvwasi_size_t path_len,
char* normalized_path,
uvwasi_size_t normalized_len) {
/* Normalizes path and stores the resulting buffer in normalized_path.
the sizes of the buffers must correspond to strlen() of the relevant
buffers, i.e. there must be room in the relevant buffers for a
NULL-byte. */
const char* cur;
char* ptr;
char* next;
Expand Down Expand Up @@ -345,7 +349,8 @@ static uvwasi_errno_t uvwasi__resolve_path_to_host(
char** resolved_path,
uvwasi_size_t* resolved_len
) {
/* Return the normalized path, but resolved to the host's real path. */
/* Return the normalized path, but resolved to the host's real path.
`path` must be a NULL-terminated string. */
char* res_path;
char* stripped_path;
int real_path_len;
Expand Down
Loading