oss-fuzz/infra/base-images/base-libfuzzer/README.md

100 lines
3.4 KiB
Markdown
Raw Normal View History

2016-10-07 18:34:42 +00:00
# base-libfuzzer
> Abstract base image for libfuzzer builders.
2016-11-30 16:26:02 +00:00
Every project image supports multiple commands that can be invoked through docker after the image is built:
2016-11-22 20:02:26 +00:00
<pre>
docker run --rm -ti ossfuzz/<b><i>$project</i></b> <i>&lt;command&gt;</i> <i>&lt;arguments...&gt;</i>
2016-11-22 20:02:26 +00:00
</pre>
2016-11-11 23:25:37 +00:00
# Supported Commands
2016-10-07 18:34:42 +00:00
| Command | Description |
|---------|-------------|
2016-11-30 16:26:02 +00:00
| `compile` (default) | build all fuzz targets
| `reproduce <fuzzer_name> <fuzzer_options>` | build all fuzz targets and run specified one with testcase `/testcase` and given options.
| `run <fuzzer_name> <fuzzer_options...>` | build all fuzz targets and run specified one with given options.
| `/bin/bash` | drop into shell, execute `compile` script to start build.
2016-10-07 18:34:42 +00:00
2016-11-22 20:02:26 +00:00
# Examples
2016-11-30 16:26:02 +00:00
- *Reproduce using latest OSS-Fuzz build:*
2016-11-22 20:02:26 +00:00
<pre>
docker run --rm -ti -v <b><i>$testcase_file</i></b>:/testcase ossfuzz/<b><i>$project</i></b> reproduce <b><i>$fuzzer</i></b>
2016-11-22 20:02:26 +00:00
</pre>
2016-11-30 16:26:02 +00:00
- *Reproduce using local source checkout:*
2016-11-22 20:02:26 +00:00
<pre>
2016-11-30 16:26:02 +00:00
docker run --rm -ti -v <b><i>$local_source_checkout_dir</i></b>:/src/<b><i>$project</i></b> \
-v <b><i>$testcase_file</i></b>:/testcase ossfuzz/<b><i>$project</i></b> reproduce <b><i>$fuzzer</i></b>
2016-11-22 20:02:26 +00:00
</pre>
# Build Configuration
Build configuration is performed through following environment variables:
| Env Variable | Description
| ------------- | --------
2016-12-05 17:44:57 +00:00
| `$SANITIZER ("address")` | Specifies sanitizer configuration to use. `address` or `undefined`.
| `$SANITIZER_FLAGS` | Specify compiler sanitizer flags directly. Overrides `$SANITIZER`.
| `$COVERAGE_FLAGS` | Specify compiler flags to use for fuzzer feedback coverage.
# Examples
- *building sqlite3 fuzzer with UBSan (`SANITIZER=undefined`):*
<pre>
docker run --rm -ti -e <i>SANITIZER</i>=<i>undefined</i> ossfuzz/sqlite3
</pre>
2016-10-13 21:02:19 +00:00
# Image Files Layout
2016-12-02 19:02:18 +00:00
| Location|Env| Description |
2016-12-02 19:02:02 +00:00
|---------| -------- | ---------- |
| `/out/` | `$OUT` | Directory to store build artifacts (fuzz targets, dictionaries, options files, seed corpus archives). |
| `/src/` | `$SRC` | Directory to checkout source files |
| `/work/`| `$WORK` | Directory for storing intermediate files |
| `/usr/lib/libFuzzingEngine.a` | `$LIB_FUZZING_ENGINE` | Location of prebuilt fuzzing engine library (e.g. libFuzzer ) that needs to be linked with all fuzz targets (`-lFuzzingEngine`).
2016-10-13 21:02:19 +00:00
While files layout is fixed within a container, the environment variables are
provided to be able to write retargetable scripts.
## Compiler Flags
2016-10-13 21:02:19 +00:00
2016-11-30 16:26:02 +00:00
You *must* use special compiler flags to build your project and fuzz targets.
2016-10-13 21:02:19 +00:00
These flags are provided in following environment variables:
| Env Variable | Description
| ------------- | --------
| `$CC` | The C compiler binary.
| `$CXX`, `$CCC` | The C++ compiler binary.
| `$CFLAGS` | C compiler flags.
| `$CXXFLAGS` | C++ compiler flags.
2016-11-30 16:26:02 +00:00
Most well-crafted build scripts will automatically use these variables. If not,
pass them manually to the build tool.
2016-10-13 21:02:19 +00:00
2016-10-07 18:34:42 +00:00
# Child Image Interface
## Sources
2016-10-07 18:34:42 +00:00
2016-11-30 16:26:02 +00:00
Child image has to checkout all sources that it needs to compile fuzz targets into
2016-12-07 19:35:53 +00:00
`$SRC` directory. When the image is executed, a directory could be mounted on top
2016-11-30 16:26:02 +00:00
of these with local checkouts using
`docker run -v $HOME/my_project:/src/my_project ...`.
2016-10-07 18:34:42 +00:00
## Other Required Files
Following files have to be added by child images:
| File Location | Description |
| ------------- | ----------- |
2016-11-30 16:26:02 +00:00
| `$SRC/build.sh` | build script to build the project and its fuzz targets |