Skip to content

Commit f7c7ee7

Browse files
freeradius: fix broken json harness (#15515)
Signed-off-by: David Korczynski <david@adalogics.com>
1 parent 50689e4 commit f7c7ee7

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

projects/freeradius/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@ FROM gcr.io/oss-fuzz-base/base-builder:ubuntu-24-04
1818
RUN apt-get update && apt-get install -y gnupg
1919
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys BE18FC5A41382202
2020
RUN echo "deb http://packages.networkradius.com/extras/ubuntu/focal focal main" > /etc/apt/sources.list.d/networkradius-extras.list
21-
RUN apt-get update && apt-get install -y libtalloc-dev libkqueue-dev libunwind-dev libjson-c-dev
21+
RUN apt-get update && apt-get install -y libtalloc-dev libkqueue-dev libunwind-dev cmake
22+
23+
# json-c source — built statically with sanitizer instrumentation in build.sh
24+
ARG JSONC_VERSION=0.18
25+
ARG JSONC_HASH=876ab046479166b869afc6896d288183bbc0e5843f141200c677b3e8dfb11724
26+
RUN set -ex \
27+
&& curl -s -L -o json-c-${JSONC_VERSION}.tar.gz https://s3.amazonaws.com/json-c_releases/releases/json-c-${JSONC_VERSION}.tar.gz \
28+
&& echo "${JSONC_HASH} json-c-${JSONC_VERSION}.tar.gz" | sha256sum -c \
29+
&& tar -xzf json-c-${JSONC_VERSION}.tar.gz \
30+
&& mv json-c-${JSONC_VERSION} $SRC/json-c
31+
ENV JSONC_PREFIX=/usr/local/json-c
2232

2333
# OpenSSL 3.0
2434
ARG OPENSSL_VERSION=3.0.15

projects/freeradius/build.sh

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,37 @@ function copy_lib
2424

2525
mkdir -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
3260
make -i -j$(nproc)

0 commit comments

Comments
 (0)