提交 0dbca9b5 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Habemus fuzzer!

上级 c65fbb25
...@@ -7,14 +7,17 @@ This document is intended for **mediasoup** developers. ...@@ -7,14 +7,17 @@ This document is intended for **mediasoup** developers.
The `worker` folder contains a `Makefile` to build the mediasoup worker subproject. The `worker` folder contains a `Makefile` to build the mediasoup worker subproject.
### `make` ### `make`
The default task runs the `Release` task unless the environment `MEDIASOUP_BUILDTYPE` is set to `Debug` (if so it runs the `Debug` task). The default task runs the `Release` task unless the environment `MEDIASOUP_BUILDTYPE` is set to `Debug` (if so it runs the `Debug` task).
### `make Release` ### `make Release`
Builds the production ready mediasoup worker binary at `worker/out/Release/`. This is the binary used in production when installing the **mediasoup** NPM module with `npm install mediasoup`. Builds the production ready mediasoup worker binary at `worker/out/Release/`. This is the binary used in production when installing the **mediasoup** NPM module with `npm install mediasoup`.
### `make Debug` ### `make Debug`
Builds a more verbose and non optimized mediasoup worker binary at `worker/out/Debug/` with some C flags enabled (such as `-O0`) and some macros defined (such as `DEBUG`, `MS_LOG_TRACE` and `MS_LOG_FILE_LINE`). Builds a more verbose and non optimized mediasoup worker binary at `worker/out/Debug/` with some C flags enabled (such as `-O0`) and some macros defined (such as `DEBUG`, `MS_LOG_TRACE` and `MS_LOG_FILE_LINE`).
...@@ -27,26 +30,58 @@ In order to instruct the **mediasoup** Node.js module to use the `Debug` mediaso ...@@ -27,26 +30,58 @@ In order to instruct the **mediasoup** Node.js module to use the `Debug` mediaso
$ MEDIASOUP_BUILDTYPE=Debug node myapp.js $ MEDIASOUP_BUILDTYPE=Debug node myapp.js
``` ```
### `make test` ### `make test`
Runs the `test-Release` task unless the environment `MEDIASOUP_BUILDTYPE` is set to `Debug` (if so it runs the `test-Debug` task). Runs the `test-Release` task unless the environment `MEDIASOUP_BUILDTYPE` is set to `Debug` (if so it runs the `test-Debug` task).
### `make test-Release` ### `make test-Release`
Builds the `mediasoup-worker-test` test unit binary at `worker/out/Release/`. Builds the `mediasoup-worker-test` test unit binary at `worker/out/Release/`.
### `make test-Debug` ### `make test-Debug`
Builds the `mediasoup-worker-test` test unit binary in `Debug` mode at `worker/out/Debug/`. Builds the `mediasoup-worker-test` test unit binary in `Debug` mode at `worker/out/Debug/`.
### `fuzzer`
Builds the `mediasoup-worker-fuzzer` target (which uses [libFuzzer](http://llvm.org/docs/LibFuzzer.html)) and generates the `worker/out/mediasoup-worker-fuzzer` binary.
**NOTE:** Linux is required with `fuzzer` capable `clang++`. `CC` environment variable must point to `clang` and `CXX` to `clang++`.
### `fuzzer-exec`
Executes the `worker/out/mediasoup-worker-fuzzer` binary.
Fuzzer command line options can be set via the `FUZZER_OPTIONS` environment variable. The `LSAN_OPTIONS` environment variable can also be used.
### `fuzzer-docker-build`
Builds a Linux image with `fuzzer` capable `clang++` that builds the `mediasoup-worker-fuzzer` target.
### `fuzzer-docker-run`
Runs a container of the Docker image created with `fuzzer-docker-build` and executes `worker/out/mediasoup-worker-fuzzer` binary.
Fuzzer command line options can be set via the `FUZZER_OPTIONS` environment variable. The `LSAN_OPTIONS` environment variable can also be used.
### `make xcode` ### `make xcode`
Builds a Xcode project for the mediasoup worker subproject. Builds a Xcode project for the mediasoup worker subproject.
### `make clean` ### `make clean`
Cleans objects and binaries related to the mediasoup worker. Cleans objects and binaries related to the mediasoup worker.
### `make clean-all` ### `make clean-all`
Cleans all the objects and binaries, including those generated for library dependencies (such as libuv, openssl and libsrtp). Cleans all the objects and binaries, including those generated for library dependencies (such as libuv, openssl and libsrtp).
...@@ -62,34 +97,43 @@ In order to tun these tasks, `gulp-cli` (version >= 1.2.2) must be globally inst ...@@ -62,34 +97,43 @@ In order to tun these tasks, `gulp-cli` (version >= 1.2.2) must be globally inst
$ npm install -g gulp-cli $ npm install -g gulp-cli
``` ```
### `gulp` ### `gulp`
The default task runs the `gulp:lint` and `gulp:test` tasks. The default task runs the `gulp:lint` and `gulp:test` tasks.
### `gulp lint` ### `gulp lint`
Runs both the `lint:node` and `lint:worker` gulp tasks. Runs both the `lint:node` and `lint:worker` gulp tasks.
### `gulp lint:node` ### `gulp lint:node`
Validates the Node.js JavaScript code/syntax. Validates the Node.js JavaScript code/syntax.
### `gulp lint:worker` ### `gulp lint:worker`
Validates the worker C++ code/syntax using [clang-format](https://clang.llvm.org/docs/ClangFormat.html) following `worker/.clang-format` rules. Validates the worker C++ code/syntax using [clang-format](https://clang.llvm.org/docs/ClangFormat.html) following `worker/.clang-format` rules.
### `gulp format` ### `gulp format`
Runs the `format:worker` gulp task. Runs the `format:worker` gulp task.
### `gulp format:worker` ### `gulp format:worker`
Rewrites worker source and include files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html). Rewrites worker source and include files using [clang-format](https://clang.llvm.org/docs/ClangFormat.html).
### `gulp tidy` ### `gulp tidy`
Runs the `tidy:worker` gulp task. Runs the `tidy:worker` gulp task.
### `gulp tidy:worker` ### `gulp tidy:worker`
Performs C++ code check using [clang-tidy](http://clang.llvm.org/extra/clang-tidy/) following following `worker/.clang-tidy` rules. Performs C++ code check using [clang-tidy](http://clang.llvm.org/extra/clang-tidy/) following following `worker/.clang-tidy` rules.
...@@ -115,10 +159,12 @@ Edit the file and remove the entry related to Utils/IP.cpp compilation unit, whi ...@@ -115,10 +159,12 @@ Edit the file and remove the entry related to Utils/IP.cpp compilation unit, whi
*NOTE:* It just works on Linux and OSX. *NOTE:* It just works on Linux and OSX.
### `gulp test` ### `gulp test`
Runs both the `test:node` and `test:worker` gulp tasks. Runs both the `test:node` and `test:worker` gulp tasks.
### `gulp test:node` ### `gulp test:node`
Runs the Node.js [test units](test/). Before it, it invokes the `make` command. Runs the Node.js [test units](test/). Before it, it invokes the `make` command.
...@@ -129,6 +175,7 @@ In order to run the JavaScript test units with the mediasoup worker in `Debug` m ...@@ -129,6 +175,7 @@ In order to run the JavaScript test units with the mediasoup worker in `Debug` m
$ MEDIASOUP_BUILDTYPE=Debug gulp test:node $ MEDIASOUP_BUILDTYPE=Debug gulp test:node
``` ```
### `gulp test:worker` ### `gulp test:worker`
Runs the mediasoup worker [test units](worker/test/). Before it, it invokes the `make test` command. Runs the mediasoup worker [test units](worker/test/). Before it, it invokes the `make test` command.
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
PYTHON ?= $(shell command -v python2 2> /dev/null || echo python) PYTHON ?= $(shell command -v python2 2> /dev/null || echo python)
.PHONY: \ .PHONY: \
default Release Debug test test-Release test-Debug fuzzer-run \ default Release Debug test test-Release test-Debug fuzzer fuzzer-exec fuzzer-fake \
fuzzer-docker-build fuzzer-docker-run xcode clean clean-all fuzzer-docker-build fuzzer-docker-run xcode clean clean-all
default: default:
...@@ -40,12 +40,19 @@ test-Debug: ...@@ -40,12 +40,19 @@ test-Debug:
$(PYTHON) ./scripts/configure.py -R mediasoup-worker-test $(PYTHON) ./scripts/configure.py -R mediasoup-worker-test
$(MAKE) BUILDTYPE=Debug -C out $(MAKE) BUILDTYPE=Debug -C out
xcode: fuzzer:
$(PYTHON) ./scripts/configure.py --format=xcode
fuzzer-run:
$(PYTHON) ./scripts/configure.py -R mediasoup-worker-fuzzer $(PYTHON) ./scripts/configure.py -R mediasoup-worker-fuzzer
$(MAKE) BUILDTYPE=Fuzzer -C out $(MAKE) BUILDTYPE=Release -C out
fuzzer-exec:
./out/Release/mediasoup-worker-fuzzer ${FUZZER_OPTIONS}
# Temporal: Just for making sure that fuzzer/fuzzer.cpp compiles in OSX
# (which does not have fuzzer support).
fuzzer-fake:
$(PYTHON) ./scripts/configure.py -R mediasoup-worker-fuzzer-fake
$(MAKE) BUILDTYPE=Release -C out
./out/Release/mediasoup-worker-fuzzer-fake
fuzzer-docker-build: fuzzer-docker-build:
ifeq ($(DOCKER_NO_CACHE),true) ifeq ($(DOCKER_NO_CACHE),true)
...@@ -54,11 +61,13 @@ else ...@@ -54,11 +61,13 @@ else
docker build -f fuzzer/Dockerfile --tag mediasoup/fuzzer:latest . docker build -f fuzzer/Dockerfile --tag mediasoup/fuzzer:latest .
endif endif
# TODO: Remove the volume. Not needed.
fuzzer-docker-run: fuzzer-docker-run:
docker run --name=mediasoupFuzzer -v $(shell pwd)/fuzzer/deleteme:/volume -it --rm mediasoup/fuzzer:latest docker run \
--init --name=mediasoupFuzzer -it --rm -e FUZZER_OPTIONS -e LSAN_OPTIONS \
mediasoup/fuzzer:latest
# docker exec mediasoupFuzzer CC=clang CXX=clang++ make fuzzer-run xcode:
$(PYTHON) ./scripts/configure.py --format=xcode
clean: clean:
$(RM) -rf out/Release/mediasoup-worker $(RM) -rf out/Release/mediasoup-worker
......
...@@ -31,11 +31,6 @@ ...@@ -31,11 +31,6 @@
{ {
'GCC_OPTIMIZATION_LEVEL': '0' 'GCC_OPTIMIZATION_LEVEL': '0'
} }
},
'Fuzzer':
{
'defines': [ 'DEBUG' ],
'cflags': [ '-g', '-O0', '-fsanitize=address,fuzzer' ]
} }
}, },
......
...@@ -27,9 +27,16 @@ COPY mediasoup-worker.gyp mediasoup-worker.gyp ...@@ -27,9 +27,16 @@ COPY mediasoup-worker.gyp mediasoup-worker.gyp
COPY common.gypi common.gypi COPY common.gypi common.gypi
COPY fips.gypi fips.gypi COPY fips.gypi fips.gypi
# Set environment variables. It's important that CC and CXX point to the
# clang/clang++ installed above.
ENV LANG="C.UTF-8" ENV LANG="C.UTF-8"
ENV CC="clang" ENV CC="clang"
ENV CXX="clang++" ENV CXX="clang++"
# CMD ["/bin/bash"] # Build the mediasoup-worker-fuzzer target.
CMD ["make", "fuzzer-run"] RUN \
set -x \
&& make fuzzer
# Eecute the mediasoup-worker-fuzzer binary.
CMD /mediasoup/worker/out/Release/mediasoup-worker-fuzzer ${FUZZER_OPTIONS}
#include "DepLibUV.hpp"
#include "DepOpenSSL.hpp"
#include "Utils.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <iostream> #include <iostream>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t len) int init()
{ {
// Initialize static stuff.
DepLibUV::ClassInit();
DepOpenSSL::ClassInit();
Utils::Crypto::ClassInit();
return 0;
}
void fuzz(const uint8_t* data, size_t len)
{
// TODO: Test everything here.
// If a RTP packet clone it, read properties, set stuff, etc.
// If RTCP the same.
// If ICE too.
RTC::RtpPacket::IsRtp(data, len); RTC::RtpPacket::IsRtp(data, len);
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len); RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len);
if (packet) if (packet)
{
std::cout << "It is a RTP packet" << std::endl;
delete packet; delete packet;
} }
else
{ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t len)
// std::cout << "It is NOT a RTP packet !!!" << std::endl; {
// std::cout << "."; static int unused = init();
}
fuzz(data, len);
return 0;
}
#ifdef MS_FUZZER_FAKE
int main(int argc, char* argv[])
{
std::cout << "OK, it compiles. Now go to Linux and run `make fuzzer-run." << std::endl;
return 0; return 0;
} }
#endif
...@@ -319,7 +319,24 @@ ...@@ -319,7 +319,24 @@
# C++ source files # C++ source files
'fuzzer/fuzzer.cpp' 'fuzzer/fuzzer.cpp'
], ],
'include_dirs': [] 'conditions':
[
[ 'OS == "linux"', {
'defines': [ 'DEBUG' ],
'cflags': [ '-g', '-O0', '-fsanitize=address,fuzzer' ],
'ldflags': [ '-fsanitize=address,fuzzer' ]
}]
]
},
# Like 'mediasoup-worker-fuzzer' target but without fuzzer (to test in OSX).
{
'target_name': 'mediasoup-worker-fuzzer-fake',
'defines': [ 'MS_LOG_STD', 'MS_FUZZER_FAKE' ],
'sources':
[
# C++ source files
'fuzzer/fuzzer.cpp'
]
} }
] ]
} }
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论