From aca25528747082f711ab5cc8b019acaad1310841 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 1 Oct 2021 15:15:24 -0600 Subject: [PATCH] sudoers: set optimization flag in LDFLAGS for the object size sanitizer (#6544) Sudo does not link executables using CFLAGS, only LDFLAGS. When building with UBSan, the compiler warns that the object size sanitizer has no effect at -O0 but is explicitly enabled. --- projects/sudoers/build.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/projects/sudoers/build.sh b/projects/sudoers/build.sh index 905450cb4..d157c9a63 100755 --- a/projects/sudoers/build.sh +++ b/projects/sudoers/build.sh @@ -28,7 +28,11 @@ else sanitizer_opts="$SANITIZER_FLAGS" fi # This is already added by --enable-fuzzer -CFLAGS="`echo \"$CFLAGS\" | sed \"s/ -fsanitize=fuzzer-no-link//\"`" +CFLAGS="`echo \"$CFLAGS\" | sed 's/ -fsanitize=fuzzer-no-link//'`" + +# Copy optimization flag to LDFLAGS for UBSan object-size check. +OPTFLAG="`echo \"$CFLAGS\" | sed 's/^.*\(-O[^ ]\).*$/\1/'`" +export LDFLAGS="${LDFLAGS:-}${LDFLAGS:+ }$OPTFLAG" # Build sudo with static libs and enable fuzzing targets. # All fuzz targets are integrated into the build process.