]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112301: Add fortify source level 3 to default compiler options (gh-121520)
authorNate Ohlson <nateohlson@gmail.com>
Thu, 18 Jul 2024 16:06:51 +0000 (13:06 -0300)
committerGitHub <noreply@github.com>
Thu, 18 Jul 2024 16:06:51 +0000 (01:06 +0900)
Misc/NEWS.d/next/Security/2024-07-08-23-39-04.gh-issue-112301.TD8G01.rst [new file with mode: 0644]
configure
configure.ac

diff --git a/Misc/NEWS.d/next/Security/2024-07-08-23-39-04.gh-issue-112301.TD8G01.rst b/Misc/NEWS.d/next/Security/2024-07-08-23-39-04.gh-issue-112301.TD8G01.rst
new file mode 100644 (file)
index 0000000..d9b4899
--- /dev/null
@@ -0,0 +1,2 @@
+Enable runtime protections for glibc to abort execution when unsafe behavior is encountered,
+for all platforms except Windows.
index 73d3bda9ddcdaafe7278b4dc30689cbbf7d20442..36f4bf7c05f7f33c7f3129b0a493a741dd7034f0 100755 (executable)
--- a/configure
+++ b/configure
@@ -9691,6 +9691,45 @@ else $as_nop
 printf "%s\n" "$as_me: WARNING: -Wtrampolines not supported" >&2;}
 fi
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -D_FORTIFY_SOURCE=3" >&5
+printf %s "checking whether C compiler accepts -D_FORTIFY_SOURCE=3... " >&6; }
+if test ${ax_cv_check_cflags___D_FORTIFY_SOURCE_3+y}
+then :
+  printf %s "(cached) " >&6
+else $as_nop
+
+  ax_check_save_flags=$CFLAGS
+  CFLAGS="$CFLAGS  -D_FORTIFY_SOURCE=3"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main (void)
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"
+then :
+  ax_cv_check_cflags___D_FORTIFY_SOURCE_3=yes
+else $as_nop
+  ax_cv_check_cflags___D_FORTIFY_SOURCE_3=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
+  CFLAGS=$ax_check_save_flags
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___D_FORTIFY_SOURCE_3" >&5
+printf "%s\n" "$ax_cv_check_cflags___D_FORTIFY_SOURCE_3" >&6; }
+if test "x$ax_cv_check_cflags___D_FORTIFY_SOURCE_3" = xyes
+then :
+  BASECFLAGS="$BASECFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
+else $as_nop
+  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: -D_FORTIFY_SOURCE=3 not supported" >&5
+printf "%s\n" "$as_me: WARNING: -D_FORTIFY_SOURCE=3 not supported" >&2;}
+fi
+
 
 case $GCC in
 yes)
index 00246a12100863a136a320be7aa4585f4cd8d2e0..5873002039886ab8aaa9db4c2506fac18ef77bfb 100644 (file)
@@ -2460,6 +2460,7 @@ AS_VAR_IF([with_strict_overflow], [yes],
 # These flags should be enabled by default for all builds.
 AX_CHECK_COMPILE_FLAG([-fstack-protector-strong], [BASECFLAGS="$BASECFLAGS -fstack-protector-strong"], [AC_MSG_WARN([-fstack-protector-strong not supported])], [-Werror])
 AX_CHECK_COMPILE_FLAG([-Wtrampolines], [BASECFLAGS="$BASECFLAGS -Wtrampolines"], [AC_MSG_WARN([-Wtrampolines not supported])], [-Werror])
+AX_CHECK_COMPILE_FLAG([-D_FORTIFY_SOURCE=3], [BASECFLAGS="$BASECFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"], [AC_MSG_WARN([-D_FORTIFY_SOURCE=3 not supported])])
 
 case $GCC in
 yes)