|
| 1 | +name: Fuzz Testing |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 4 * * 1' # Weekly Monday 4am UTC |
| 6 | + workflow_dispatch: # Manual trigger |
| 7 | + pull_request: |
| 8 | + branches: [ '*' ] |
| 9 | + |
| 10 | +jobs: |
| 11 | + fuzz: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + timeout-minutes: 30 |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + include: |
| 18 | + # Full fuzz run (weekly/manual) - 10 minutes |
| 19 | + - name: fuzz-full |
| 20 | + fuzz_time: 600 |
| 21 | + smoke_only: false |
| 22 | + # Quick smoke test (PR) - 60 seconds |
| 23 | + - name: fuzz-smoke |
| 24 | + fuzz_time: 60 |
| 25 | + smoke_only: true |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout wolfMQTT |
| 29 | + uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: ASLR workaround |
| 32 | + run: sudo sysctl vm.mmap_rnd_bits=28 |
| 33 | + |
| 34 | + - name: Build fuzz target |
| 35 | + run: | |
| 36 | + ./autogen.sh |
| 37 | + CC=clang ./configure --enable-broker --enable-v5 --enable-fuzz \ |
| 38 | + --disable-tls --disable-examples \ |
| 39 | + CFLAGS="-fsanitize=fuzzer-no-link,address -fno-omit-frame-pointer -g -O1" \ |
| 40 | + LDFLAGS="-fsanitize=address" |
| 41 | + make -j$(nproc) |
| 42 | +
|
| 43 | + - name: Generate seed corpus |
| 44 | + run: python3 src/fuzz/gen_corpus.py |
| 45 | + |
| 46 | + - name: Run fuzzer |
| 47 | + env: |
| 48 | + ASAN_OPTIONS: "detect_leaks=1:abort_on_error=1:symbolize=1" |
| 49 | + run: | |
| 50 | + echo "Fuzzing for ${{ matrix.fuzz_time }} seconds..." |
| 51 | + timeout ${{ matrix.fuzz_time }} \ |
| 52 | + ./src/fuzz/broker_fuzz \ |
| 53 | + src/fuzz/corpus/ \ |
| 54 | + -dict=src/fuzz/mqtt.dict \ |
| 55 | + -max_len=4096 \ |
| 56 | + -timeout=10 \ |
| 57 | + -rss_limit_mb=2048 \ |
| 58 | + -print_final_stats=1 \ |
| 59 | + || FUZZ_RC=$? |
| 60 | + # timeout returns 124 on normal expiry, fuzzer returns 0 on no crash |
| 61 | + if [ "${FUZZ_RC:-0}" -eq 124 ] || [ "${FUZZ_RC:-0}" -eq 0 ]; then |
| 62 | + echo "Fuzzer completed without crashes" |
| 63 | + else |
| 64 | + echo "Fuzzer found crashes (exit code $FUZZ_RC)" |
| 65 | + ls -la crash-* 2>/dev/null || true |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Upload crash artifacts |
| 70 | + if: failure() |
| 71 | + uses: actions/upload-artifact@v4 |
| 72 | + with: |
| 73 | + name: fuzz-crashes-${{ matrix.name }} |
| 74 | + path: | |
| 75 | + crash-* |
| 76 | + oom-* |
| 77 | + timeout-* |
| 78 | + retention-days: 30 |
| 79 | + if-no-files-found: ignore |
0 commit comments