Skip to content

Commit c9b0706

Browse files
Add fuzzing by way of ClusterFuzzLite
Signed-off-by: David Korczynski <david@adalogics.com>
1 parent 4ade42d commit c9b0706

File tree

6 files changed

+84
-0
lines changed

6 files changed

+84
-0
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+
4+
COPY . $SRC/fast-cpp-csv-parser
5+
COPY .clusterfuzzlite/build.sh $SRC/build.sh
6+
WORKDIR $SRC/fast-cpp-csv-parser

.clusterfuzzlite/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# ClusterFuzzLite set up
2+
3+
This folder contains a fuzzing set for [ClusterFuzzLite](https://google.github.io/clusterfuzzlite).
4+

.clusterfuzzlite/build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash -eu
2+
# Supply build instructions
3+
# Use the following environment variables to build the code
4+
# $CXX: c++ compiler
5+
# $CC: c compiler
6+
# CFLAGS: compiler flags for C files
7+
# CXXFLAGS: compiler flags for CPP files
8+
# LIB_FUZZING_ENGINE: linker flag for fuzzing harnesses
9+
10+
# Copy all fuzzer executables to $OUT/
11+
12+
# Copy all fuzzer executables to $OUT/
13+
$CXX $CFLAGS $LIB_FUZZING_ENGINE \
14+
$SRC/fast-cpp-csv-parser/.clusterfuzzlite/parse_fuzzer.cpp \
15+
-o $OUT/parse_fuzzer \
16+
-I$SRC/fast-cpp-csv-parser

.clusterfuzzlite/parse_fuzzer.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
#include "csv.h"
3+
#include <unistd.h>
4+
5+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
6+
char filename[256];
7+
sprintf(filename, "/tmp/libfuzzer.%d.csv", getpid());
8+
FILE *fp = fopen(filename, "wb");
9+
if (!fp)
10+
return 0;
11+
fwrite(data, size, 1, fp);
12+
fclose(fp);
13+
14+
io::CSVReader<3> in(filename);
15+
try {
16+
in.read_header(io::ignore_extra_column, "vendor", "col2", "col3");
17+
std::string vendor;
18+
int col2;
19+
double col3;
20+
while (in.read_row(vendor, col2, col3)) {
21+
}
22+
} catch (...) {
23+
}
24+
25+
unlink(filename);
26+
return 0;
27+
}

.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_pr.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
github-token: ${{ secrets.GITHUB_TOKEN }}
27+
fuzz-seconds: 100
28+
mode: 'code-change'
29+
report-unreproducible-crashes: false
30+
sanitizer: ${{ matrix.sanitizer }}

0 commit comments

Comments
 (0)