* Python CI

* fix testcase

* fix yml

* Fixing test

* format python

* cleanup
This commit is contained in:
Dominik Maier 2023-01-31 05:04:19 +01:00 committed by GitHub
parent fc8c92514f
commit d73fb92ddf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 4 deletions

View File

@ -157,7 +157,9 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- name: Run a maturin build - name: Run a maturin build
run: cd ./bindings/pylibafl && maturin build run: cd ./bindings/pylibafl && python3 -m venv .env && . .env/bin/activate && maturin develop && ./test.sh
- name: Run python test
run: . ./bindings/pylibafl/.env/bin/activate && cd ./fuzzers/baby_fuzzer && python3 baby_fuzzer.py | grep "Bye"
fuzzers: fuzzers:
strategy: strategy:

View File

@ -1,5 +1,8 @@
from pylibafl.libafl import * from pylibafl.libafl import *
import ctypes import ctypes
import platform
MAP_SIZE = 4096
class FooObserver(BaseObserver): class FooObserver(BaseObserver):
@ -33,11 +36,16 @@ class FooExecutor(BaseExecutor):
return (self.h)(input) return (self.h)(input)
libc = ctypes.cdll.LoadLibrary("libc.so.6") if platform.system() == "Darwin":
libc = ctypes.cdll.LoadLibrary("libc.dylib")
else:
libc = ctypes.cdll.LoadLibrary("libc.so.6")
area_ptr = libc.calloc(1, 4096) # Get a buffer to use for our map observer
libc.calloc.restype = ctypes.c_void_p
area_ptr = libc.calloc(1, MAP_SIZE)
observer = StdMapObserverI8("mymap", area_ptr, 4096) observer = StdMapObserverI8("mymap", area_ptr, MAP_SIZE)
m = observer.as_map_observer() m = observer.as_map_observer()
@ -69,7 +77,12 @@ mgr = SimpleEventManager(monitor.as_monitor())
def harness(buf) -> ExitKind: def harness(buf) -> ExitKind:
"""
The harness fn that the fuzzer will execute in a loop
"""
# print(buf) # print(buf)
# set the observer map byte from python
m[0] = 1 m[0] = 1
if len(buf) > 0 and buf[0] == ord("a"): if len(buf) > 0 and buf[0] == ord("a"):
m[1] = 1 m[1] = 1
@ -91,4 +104,6 @@ stage_tuple_list = StagesTuple([stage.as_stage()])
fuzzer.add_input(state, executor.as_executor(), mgr.as_manager(), b"\0\0") fuzzer.add_input(state, executor.as_executor(), mgr.as_manager(), b"\0\0")
print("Starting to fuzz from python!")
fuzzer.fuzz_loop(executor.as_executor(), state, mgr.as_manager(), stage_tuple_list) fuzzer.fuzz_loop(executor.as_executor(), state, mgr.as_manager(), stage_tuple_list)

11
bindings/pylibafl/test.sh Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
timeout 10 python3 ./test.py
export exit_code=$?
if [ $exit_code -eq 124 ]; then
# 124 = timeout happened. All good.
exit 0
else
exit $exit_code
fi