summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Simons <simons@cryp.to>2023-02-20 17:37:01 +0100
committerGitHub <noreply@github.com>2023-02-20 17:37:01 +0100
commitb834394b4e1e7a9110d35fc71e59c566d9cf66b3 (patch)
tree25db408fbaa4623ca064b1b90651add3a8a42ccd
parent23b15c928fc7bf94169445ac463b2b28783e7b94 (diff)
parent804e6190d75f7f0f8eb251c21d05a55ff0f35c12 (diff)
downloadautoconf-archive-b834394b4e1e7a9110d35fc71e59c566d9cf66b3.tar.gz
Merge pull request #269 from rurban/fortify3
AX_ADD_FORTIFY_SOURCE: add -D_FORTIFY_SOURCE=3 check
-rw-r--r--m4/ax_add_fortify_source.m447
1 files changed, 44 insertions, 3 deletions
diff --git a/m4/ax_add_fortify_source.m4 b/m4/ax_add_fortify_source.m4
index 9d921b8..8d15b8f 100644
--- a/m4/ax_add_fortify_source.m4
+++ b/m4/ax_add_fortify_source.m4
@@ -10,7 +10,7 @@
#
# Check whether -D_FORTIFY_SOURCE=2 can be added to CPPFLAGS without macro
# redefinition warnings, other cpp warnings or linker. Some distributions
-# (such as Gentoo Linux) enable _FORTIFY_SOURCE globally in their
+# (such as Ubuntu or Gentoo Linux) enable _FORTIFY_SOURCE globally in their
# compilers, leading to unnecessary warnings in the form of
#
# <command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
@@ -29,7 +29,7 @@
# LICENSE
#
# Copyright (c) 2017 David Seifert <soap@gentoo.org>
-# Copyright (c) 2019 Reini Urban <rurban@cpan.org>
+# Copyright (c) 2019, 2023 Reini Urban <rurban@cpan.org>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
@@ -42,6 +42,46 @@ AC_DEFUN([AX_ADD_FORTIFY_SOURCE],[
ac_save_cflags=$CFLAGS
ac_cwerror_flag=yes
AX_CHECK_COMPILE_FLAG([-Werror],[CFLAGS="$CFLAGS -Werror"])
+ ax_add_fortify_3_failed=
+ AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=3 to CPPFLAGS])
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM([],
+ [[
+ #ifndef _FORTIFY_SOURCE
+ return 0;
+ #else
+ _FORTIFY_SOURCE_already_defined;
+ #endif
+ ]]
+ )],
+ AC_LINK_IFELSE([
+ AC_LANG_SOURCE([[
+ #define _FORTIFY_SOURCE 3
+ #include <string.h>
+ int main() {
+ char *s = " ";
+ strcpy(s, "x");
+ return strlen(s)-1;
+ }
+ ]]
+ )],
+ [
+ AC_MSG_RESULT([yes])
+ CFLAGS=$ac_save_cflags
+ CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=3"
+ ], [
+ AC_MSG_RESULT([no])
+ CFLAGS=$ac_save_cflags
+ ax_add_fortify_3_failed=1
+ ],
+ ),
+ [
+ AC_MSG_RESULT([no])
+ CFLAGS=$ac_save_cflags
+ ax_add_fortify_3_failed=1
+ ])
+ if test -n "$ax_add_fortify_3_failed"
+ then
AC_MSG_CHECKING([whether to add -D_FORTIFY_SOURCE=2 to CPPFLAGS])
AC_LINK_IFELSE([
AC_LANG_PROGRAM([],
@@ -49,7 +89,7 @@ AC_DEFUN([AX_ADD_FORTIFY_SOURCE],[
#ifndef _FORTIFY_SOURCE
return 0;
#else
- this_is_an_error;
+ _FORTIFY_SOURCE_already_defined;
#endif
]]
)],
@@ -77,4 +117,5 @@ AC_DEFUN([AX_ADD_FORTIFY_SOURCE],[
AC_MSG_RESULT([no])
CFLAGS=$ac_save_cflags
])
+ fi
])