From ec9df4527fa3242d55b7cf4c82d2fb5d28f8987b Mon Sep 17 00:00:00 2001 From: Zdenek Dohnal Date: Fri, 28 Apr 2023 10:00:27 +0200 Subject: [PATCH] configure: Use _FORTIFY_SOURCE if not defined already If _FORTIFY_SOURCE is not defined in flags, use its level 3. Backported from libcups. --- config-scripts/cups-compiler.m4 | 6 ++++-- configure | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/config-scripts/cups-compiler.m4 b/config-scripts/cups-compiler.m4 index 266d909ed3..6a4f4ba87e 100644 --- a/config-scripts/cups-compiler.m4 +++ b/config-scripts/cups-compiler.m4 @@ -105,11 +105,13 @@ AS_IF([test -n "$GCC"], [ AS_IF([test x$enable_sanitizer = xyes], [ # Use -fsanitize=address with debugging... OPTIM="$OPTIM -g -fsanitize=address" + ], [echo "$CXXFLAGS $CFLAGS" | grep -q _FORTIFY_SOURCE], [ + # Don't add _FORTIFY_SOURCE if it is already there ], [ # Otherwise use the Fortify enhancements to catch any unbounded # string operations... - CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2" - CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2" + CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=3" + CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=3" ]) # Default optimization options... diff --git a/configure b/configure index 40d9e7a714..3af6165129 100755 --- a/configure +++ b/configure @@ -8098,12 +8098,17 @@ then : # Use -fsanitize=address with debugging... OPTIM="$OPTIM -g -fsanitize=address" +elif echo "$CXXFLAGS $CFLAGS" | grep -q _FORTIFY_SOURCE +then : + + # Don't add _FORTIFY_SOURCE if it is already there + else $as_nop # Otherwise use the Fortify enhancements to catch any unbounded # string operations... - CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2" - CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2" + CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=3" + CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=3" fi -- 2.47.2