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-10-26 15:28:38 +00:00
2016-11-22 20:02:26 +00:00
< pre >
2016-11-29 19:22:48 +00:00
docker run --rm -ti ossfuzz/< b > < i > $project< / i > < / b > < i > < command> < / i > < i > < arguments...> < / i >
2016-11-22 20:02:26 +00:00
< / pre >
2016-11-29 19:22:48 +00:00
2016-11-11 23:25:37 +00:00
# Supported Commands
2016-10-07 18:34:42 +00:00
2016-10-26 15:28:38 +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.
2016-10-26 15:28:38 +00:00
| `/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 >
2016-11-29 19:22:48 +00:00
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 > \
2016-11-29 19:22:48 +00:00
-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-12-02 18:58:51 +00:00
# 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` .
2016-12-13 18:37:03 +00:00
| `$COVERAGE_FLAGS` | Specify compiler flags to use for fuzzer feedback coverage.
2016-12-02 18:58:51 +00:00
# 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 |
2016-12-07 19:41:08 +00:00
| `/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
2016-12-07 19:41:08 +00:00
While files layout is fixed within a container, the environment variables are
2016-11-18 19:16:38 +00:00
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-11-18 19:16:38 +00:00
2016-10-07 18:34:42 +00:00
# Child Image Interface
2016-10-18 22:37:23 +00:00
## 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
2016-11-29 19:22:48 +00:00
`docker run -v $HOME/my_project:/src/my_project ...` .
2016-10-07 18:34:42 +00:00
2016-10-18 22:37:23 +00:00
## Other Required Files
2016-10-10 20:21:45 +00:00
2016-10-18 22:37:23 +00:00
Following files have to be added by child images:
2016-10-10 20:21:45 +00:00
2016-10-18 22:37:23 +00:00
| File Location | Description |
| ------------- | ----------- |
2016-11-30 16:26:02 +00:00
| `$SRC/build.sh` | build script to build the project and its fuzz targets |