1717# DB_ASSERT in __memp_fopen, or a recovery-failure panic), which is by-design
1818# diagnostic behavior, not the OOB/FPE crash class this gate guards against.
1919#
20+ # libdb ASan instrumentation:
21+ # Some crash classes (a heap-buffer-overflow / use-after-free / double-free
22+ # *inside* libdb's own allocations -- e.g. the __part_verify type-confusion
23+ # OOB write) are only observable when libdb itself is compiled with
24+ # AddressSanitizer; a harness-only ASan build (libdb.a plain) cannot see
25+ # them. If a build_unix built with `CFLAGS=-fsanitize=address` (ASan only,
26+ # NOT undefined -- UBSan flags libdb's pervasive base+offset pointer idioms)
27+ # is available, point LIBDB_BUILD at it to catch those. This gate
28+ # auto-builds one under build_asan_gate/ when LIBDB_ASAN=1 (default on).
29+ #
2030# Usage: ./check-crashes.sh
21- # Env: CC, LIBDB_BUILD (see run.sh)
31+ # Env: CC, LIBDB_BUILD (see run.sh), LIBDB_ASAN (1=build+use an ASan libdb)
2232#
2333# Run from test/fuzz/ inside a `nix develop` shell.
2434
@@ -27,6 +37,27 @@ set -eu
2737HERE=$( CDPATH= cd -- " $( dirname -- " $0 " ) " && pwd)
2838cd " $HERE "
2939
40+ CC=${CC:- clang}
41+ LIBDB_ASAN=${LIBDB_ASAN:- 1}
42+
43+ # Build (once) an ASan-instrumented libdb so a memory fault *inside* libdb is
44+ # caught, then link the standalone harnesses against it. ASan only -- UBSan
45+ # would fire on libdb's legitimate base+offset pointer arithmetic. The
46+ # harness's own SAN flags in run.sh still add UBSan to the harness .c, so we
47+ # neutralise it for the lib by exporting an ASan-only LIBDB build here.
48+ if [ " $LIBDB_ASAN " = " 1" ] && [ -z " ${LIBDB_BUILD:- } " ]; then
49+ GATE_BUILD=" $HERE /../../build_asan_gate"
50+ if [ ! -f " $GATE_BUILD /libdb.a" ]; then
51+ mkdir -p " $GATE_BUILD "
52+ ( cd " $GATE_BUILD " &&
53+ ../dist/configure --enable-debug \
54+ CC=" $CC " CFLAGS=" -fsanitize=address -g -O1" > configure.log 2>&1 &&
55+ make -j4 > build.log 2>&1 ) ||
56+ { echo " warning: ASan libdb build failed; falling back to plain lib" >&2 ; }
57+ fi
58+ [ -f " $GATE_BUILD /libdb.a" ] && export LIBDB_BUILD=" $GATE_BUILD "
59+ fi
60+
3061# Build the standalone (no-libFuzzer) drivers for every harness once.
3162FUZZ_STANDALONE=1 ./run.sh build
3263
0 commit comments