Skip to content

Commit 6eeddba

Browse files
Add cflite and document normalize path (#280)
* make it clear resolve_path expects null-terminated string Signed-off-by: David Korczynski <[email protected]>
1 parent c8d4f01 commit 6eeddba

File tree

7 files changed

+98
-1
lines changed

7 files changed

+98
-1
lines changed

.clusterfuzzlite/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM gcr.io/oss-fuzz-base/base-builder
2+
RUN apt-get update && apt-get install -y make autoconf automake libtool
3+
COPY . $SRC/uvwasi
4+
COPY .clusterfuzzlite/build.sh $SRC/build.sh
5+
COPY .clusterfuzzlite/*.c $SRC/
6+
WORKDIR uvwasi

.clusterfuzzlite/build.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Disable building of shared library
2+
#sed -i 's/add\_library(uvwasi SHARED/# /g' CMakeLists.txt
3+
mkdir build
4+
cd build
5+
cmake ../
6+
make uvwasi_a
7+
8+
$CC $CFLAGS $LIB_FUZZING_ENGINE ../.clusterfuzzlite/fuzz_normalize_path.c \
9+
-o $OUT/fuzz_normalize_path \
10+
./libuvwasi_a.a _deps/libuv-build/libuv_a.a \
11+
-I$SRC/uvwasi/include -I$PWD/_deps/libuv-src/include/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <stdint.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
#include "../src/path_resolver.h"
6+
7+
#define BUFFER_SIZE 128
8+
9+
char normalized_buffer[BUFFER_SIZE+1];
10+
11+
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
12+
char *new_str = (char *)malloc(size + 1);
13+
if (new_str == NULL) {
14+
return 0;
15+
}
16+
memcpy(new_str, data, size);
17+
new_str[size] = '\0';
18+
19+
memset(normalized_buffer, 0, BUFFER_SIZE);
20+
21+
uvwasi__normalize_path(new_str, size, normalized_buffer, BUFFER_SIZE);
22+
23+
free(new_str);
24+
return 0;
25+
}

.clusterfuzzlite/project.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: c

.github/workflows/cflite.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: ClusterFuzzLite PR fuzzing
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
branches: [ main ]
6+
permissions: read-all
7+
jobs:
8+
PR:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
sanitizer: [address]
14+
steps:
15+
- name: Build Fuzzers (${{ matrix.sanitizer }})
16+
id: build
17+
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
18+
with:
19+
sanitizer: ${{ matrix.sanitizer }}
20+
language: c
21+
bad-build-check: false
22+
- name: Run Fuzzers (${{ matrix.sanitizer }})
23+
id: run
24+
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
25+
with:
26+
fuzz-seconds: 100
27+
mode: 'code-change'
28+
report-unreproducible-crashes: false
29+
sanitizer: ${{ matrix.sanitizer }}

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,26 @@ To do a release complete the following steps:
25002500
* Update uvwasi in Node.js or any projects you want to update - there are several
25012501
other projects that use uvwasi.
25022502

2503+
## Running fuzzers locally
2504+
2505+
We support fuzzing by way of [ClusterFuzzLite](https://google.github.io/clusterfuzzlite/),
2506+
which is run automatically against pull requests. You can run these fuzzers
2507+
locally with the [OSS-Fuzz](https://github.com/google/oss-fuzz) fuzzing
2508+
infrastructure, using the following steps:
2509+
2510+
```sh
2511+
git clone https://github.com/google/oss-fuzz
2512+
git clone https://github.com/nodejs/uvwasi
2513+
cd uvwasi
2514+
2515+
# Build the fuzzers in .clusterfuzzlite
2516+
python3 ../oss-fuzz/infra/helper.py build_fuzzers --external $PWD
2517+
2518+
# Run the fuzzer for 10 seconds
2519+
python3 ../oss-fuzz/infra/helper.py run_fuzzer --external $PWD fuzz_normalize_path -- -max_total_time=10
2520+
```
2521+
2522+
25032523
[WASI]: https://github.com/WebAssembly/WASI
25042524
[libuv]: https://github.com/libuv/libuv
25052525
[preview 1]: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md

src/path_resolver.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ uvwasi_errno_t uvwasi__normalize_path(const char* path,
7272
uvwasi_size_t path_len,
7373
char* normalized_path,
7474
uvwasi_size_t normalized_len) {
75+
/* Normalizes path and stores the resulting buffer in normalized_path.
76+
the sizes of the buffers must correspond to strlen() of the relevant
77+
buffers, i.e. there must be room in the relevant buffers for a
78+
NULL-byte. */
7579
const char* cur;
7680
char* ptr;
7781
char* next;
@@ -345,7 +349,8 @@ static uvwasi_errno_t uvwasi__resolve_path_to_host(
345349
char** resolved_path,
346350
uvwasi_size_t* resolved_len
347351
) {
348-
/* Return the normalized path, but resolved to the host's real path. */
352+
/* Return the normalized path, but resolved to the host's real path.
353+
`path` must be a NULL-terminated string. */
349354
char* res_path;
350355
char* stripped_path;
351356
int real_path_len;

0 commit comments

Comments
 (0)