Repository Public
1#!/bin/bash2# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project : QYVORA8# File : security/fuzzing/campaign.sh9# Module : Security10# Repository : https://git.spboucher.ai/qyvora11# Project Website : Not specified12# Created : 2026-12-0413# Last Modified : 2026-12-0414#15# Author : Simon-Pierre Boucher16# Position : Professor of Finance17# Institution : Université du Québec en Outaouais (UQO)18# Organization : SP Boucher19# Website : https://spboucher.ai20# Git : https://git.spboucher.ai21#22# Preferred Contact: contact@spboucher.ai23# Development : dev@spboucher.ai24# Support : support@spboucher.ai25# Security/Admin : admin@spboucher.ai26#27# Copyright (c) 202628# Simon-Pierre Boucher29# All rights reserved where applicable. This file is governed by the30# applicable project license, copyright notices and relevant law.31# Existing third-party rights and notices remain unaffected.32#33# License : None specified (no license file in this repository)34#35# Do not embed credentials, private keys, access tokens,36# certificates or confidential personal information.37#38# =============================================================================39# END OF SP BOUCHER SOURCE HEADER40# =============================================================================4142# Fuzzing campaign on one machine. Run from a copy of the repository (the runner43# security/audit/runners/fuzz.py copies the tree to <node>:qyvora-build/audit-fuzz/ and calls this).44#45# security/fuzzing/campaign.sh SECONDS WORKERS [OUTDIR]46#47# Two builds of qyfuzz run side by side, each with half of the workers:48# plain release build, as shipped: fastest, real release-mode traps, feedback = outcome classes only49# coverage release build with AddressSanitizer and SanitizerCoverage inline 8-bit counters:50# edge-coverage feedback and memory-error detection, about ten times slower51# Results: OUTDIR/plain.json, OUTDIR/coverage.json, OUTDIR/host.json, OUTDIR/crashes/<target>/.52# QY_FUZZ_TARGETS selects targets (default all). QY_FUZZ_NO_COVERAGE=1 skips the instrumented build.53set -u54SECONDS_BUDGET=${1:?seconds}55WORKERS=${2:?workers}56ROOT="$(cd "$(dirname "$0")/../.." && pwd)"57OUT=${3:-$ROOT/security/fuzzing/work/campaign}58TARGETS=${QY_FUZZ_TARGETS:-all}59TESTS="$ROOT/security/tests"60WORK="$ROOT/security/fuzzing/work"61mkdir -p "$OUT/crashes" "$WORK"62rm -f "$OUT/plain.json" "$OUT/coverage.json" "$OUT/build-plain.log" "$OUT/build-coverage.log"6364cd "$TESTS" || exit 265swift build -c release -Xswiftc -enable-testing --product qyfuzz --scratch-path "$TESTS/.build" > "$OUT/build-plain.log" 2>&166PLAIN_OK=$?67COV_OK=168if [ "${QY_FUZZ_NO_COVERAGE:-0}" != "1" ]; then69 swift build -c release -Xswiftc -enable-testing --sanitize=address -Xswiftc -sanitize-coverage=edge,inline-8bit-counters \70 --product qyfuzz --scratch-path "$TESTS/.build-cov" > "$OUT/build-coverage.log" 2>&171 COV_OK=$?72fi7374W_COV=075W_PLAIN=$WORKERS76if [ $COV_OK -eq 0 ] && [ "$WORKERS" -ge 2 ]; then77 W_COV=$((WORKERS / 2))78 W_PLAIN=$((WORKERS - W_COV))79fi8081cat > "$OUT/host.json" <<EOF82{"host": "$(hostname -s)", "cores": $(sysctl -n hw.ncpu), "model": "$(sysctl -n hw.model)", "os": "$(sw_vers -productVersion)",83 "swift": "$(swift --version 2>&1 | grep -o 'Swift version [0-9.]*' | head -1)", "load_before": "$(uptime | sed 's/.*load averages*: //')",84 "seconds": $SECONDS_BUDGET, "workers": $WORKERS, "workers_plain": $W_PLAIN, "workers_coverage": $W_COV,85 "build_plain_exit": $PLAIN_OK, "build_coverage_exit": $COV_OK, "started": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"}86EOF8788PIDS=""89if [ $PLAIN_OK -eq 0 ]; then90 "$TESTS/.build/release/qyfuzz" run --target "$TARGETS" --seconds "$SECONDS_BUDGET" --workers "$W_PLAIN" \91 --work "$WORK/plain" --crashes "$OUT/crashes" --json "$OUT/plain.json" > "$OUT/plain.log" 2>&1 &92 PIDS="$PIDS $!"93fi94if [ $COV_OK -eq 0 ] && [ $W_COV -gt 0 ]; then95 "$TESTS/.build-cov/release/qyfuzz" run --target "$TARGETS" --seconds "$SECONDS_BUDGET" --workers "$W_COV" \96 --work "$WORK/coverage" --crashes "$OUT/crashes" --json "$OUT/coverage.json" > "$OUT/coverage.log" 2>&1 &97 PIDS="$PIDS $!"98fi99for p in $PIDS; do wait "$p"; done100echo "campaign finished: $(ls "$OUT"/*.json 2>/dev/null | tr '\n' ' ')"101[ $PLAIN_OK -eq 0 ] || exit 3102exit 0103