@@ -24,9 +24,37 @@ function copy_lib
2424
2525mkdir -p $OUT /lib
2626
27+ # Build json-c statically with the current sanitizer CFLAGS so it is
28+ # instrumented and gets linked into fuzzer_json with no runtime shared
29+ # library dependency on libjson-c.so.
30+ mkdir -p $SRC /json-c-build
31+ pushd $SRC /json-c-build
32+ cmake $SRC /json-c \
33+ -DCMAKE_INSTALL_PREFIX=${JSONC_PREFIX} \
34+ -DCMAKE_BUILD_TYPE=Release \
35+ -DBUILD_SHARED_LIBS=OFF \
36+ -DBUILD_STATIC_LIBS=ON \
37+ -DDISABLE_WERROR=ON \
38+ -DBUILD_TESTING=OFF \
39+ -DCMAKE_C_COMPILER=" $CC " \
40+ -DCMAKE_C_FLAGS=" $CFLAGS -fPIC"
41+ make -j$( nproc)
42+ make install
43+ popd
44+
2745# git apply --ignore-whitespace $SRC/patch.diff
28- # build project
29- ./configure --enable-fuzzer --enable-coverage --enable-address-sanitizer
46+ # fuzzer_json.mk doesn't pull in the json-c include path; inject it and
47+ # force static linking against our instrumented libjson-c.a.
48+ sed -i \
49+ -e " s|^SRC_CFLAGS\s*+= -I\$ (top_builddir)/src/lib/json/|SRC_CFLAGS += -I\$ (top_builddir)/src/lib/json/ -I${JSONC_PREFIX} /include|" \
50+ -e " s|-ljson-c|${JSONC_PREFIX} /lib/libjson-c.a|" \
51+ src/bin/fuzzer_json.mk
52+ cat src/bin/fuzzer_json.mk
53+
54+ # build project — point FreeRADIUS' json-c probe at our static build
55+ ./configure --enable-fuzzer --enable-coverage --enable-address-sanitizer \
56+ --with-jsonc-include-dir=${JSONC_PREFIX} /include \
57+ --with-jsonc-lib-dir=${JSONC_PREFIX} /lib
3058# make tries to compile regular programs as fuzz targets
3159# so -i flag ignores these errors
3260make -i -j$( nproc)
0 commit comments