Skip to content

Commit

Permalink
Add cflite and document normalize path
Browse files Browse the repository at this point in the history
Fixes: #251

Signed-off-by: David Korczynski <[email protected]>
  • Loading branch information
DavidKorczynski committed Aug 30, 2024
1 parent c8d4f01 commit 13aff19
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
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 }}
4 changes: 4 additions & 0 deletions 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

0 comments on commit 13aff19

Please sign in to comment.