Moved fuzz dir to test/fuzz

Extended contributing document to testing and licensing
This commit is contained in:
Olof hagsand 2021-10-10 18:03:33 +02:00
parent edbbb43e1f
commit 8ede8a87b2
29 changed files with 62 additions and 1053 deletions

61
test/fuzz/cli/README.md Normal file
View file

@ -0,0 +1,61 @@
# Clixon fuzzing
This dir contains code for fuzzing clixon cli.
## Prereqs
Install AFL, see [..](..)
Build and install a clixon system (in particular the backend, the CLI will be replaced)
Build and install CLIgen statically:
```
./configure LINKAGE=static INSTALLFLAGS="" CC=/usr/bin/afl-clang-fast
```
## Build
Build clixon cli statically with the afl-clang compiler:
```
CC=/usr/bin/afl-clang-fast LINKAGE=static INSTALLFLAGS="" ./configure # Dont care about restconf
make clean
cd apps/cli
make clixon_cli
sudo make install
```
To link an example plugin properly it gets a little more complex::
- First, you need to identify which example plugins you want to link. Add these to `EXTRAS` variable
- Configure and compile those plugins, where the `clixon_plugin_init()` function is removed.
- Configure and compile the cli WITH the `EXTRAS` variable set.
Below is an example of how to do this for the main example. You can replace the main example plugins with another application:
```
CC=/usr/bin/afl-clang-fast CFLAGS="-O2 -Wall -DCLIXON_STATIC_PLUGINS" LINKAGE=static INSTALLFLAGS="" ./configure
make clean
make
sudo make install
cd example # Compile and install application plugins (here main example)
make clean
make
sudo make install
cd ..
cd apps/cli # Compile and install clixon_cli with pre-compiled plugins
rm clixon_cli
EXTRAS="../../example/main/example_cli.o" make clixon_cli
sudo make install
```
## Run tests
Run the script `runfuzz.sh` to run one test with a cli spec and an input string, eg:
```
./runfuzz.sh
```
After (or during) the test, investigate results in the output dir.

View file

@ -0,0 +1,3 @@
set table parameter a value 42
table
example 42

View file

@ -0,0 +1 @@
show configuration

View file

@ -0,0 +1,2 @@
validate
commit

52
test/fuzz/cli/runfuzz.sh Executable file
View file

@ -0,0 +1,52 @@
#!/usr/bin/env bash
# Run a fuzzing test using american fuzzy lop
set -eux
if [ $# -ne 0 ]; then
echo "usage: $0\n"
exit 255
fi
APPNAME=example
cfg=conf.xml
cat <<EOF > $cfg
<clixon-config xmlns="http://clicon.org/config">
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_FEATURE>*:*</CLICON_FEATURE>
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
<CLICON_YANG_MODULE_MAIN>clixon-example</CLICON_YANG_MODULE_MAIN>
<CLICON_SOCK>/usr/local/var/example/example.sock</CLICON_SOCK>
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
<CLICON_STARTUP_MODE>init</CLICON_STARTUP_MODE>
<CLICON_MODULE_LIBRARY_RFC7895>false</CLICON_MODULE_LIBRARY_RFC7895>
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
<CLICON_CLI_GENMODEL_COMPLETION>1</CLICON_CLI_GENMODEL_COMPLETION>
<CLICON_CLI_GENMODEL_TYPE>VARS</CLICON_CLI_GENMODEL_TYPE>
<CLICON_CLI_AUTOCLI_EXCLUDE>clixon-restconf</CLICON_CLI_AUTOCLI_EXCLUDE>
<CLICON_CLI_LINESCROLLING>0</CLICON_CLI_LINESCROLLING>
<CLICON_CLI_TAB_MODE>0</CLICON_CLI_TAB_MODE>
</clixon-config>
EOF
# Kill previous
sudo clixon_backend -z -f $cfg -s init
# Start backend
sudo clixon_backend -f $cfg -s init
MEGS=500 # memory limit for child process (50 MB)
# remove input and input dirs
#test ! -d input || rm -rf input
test ! -d output || rm -rf output
# create if dirs dont exists
#test -d input || mkdir input
test -d output || mkdir output
# Run script
afl-fuzz -i input -o output -m $MEGS -- clixon_cli -f $cfg