shithub: sox

Download patch

ref: 256b7e37d14de2e5303a6f899be8cdffda8e1661
parent: 80123617fccf01cc375afeff9177027e3d510567
author: Chris Bagwell <chris@cnpbagwell.com>
date: Wed Oct 29 18:19:53 EDT 2014

Switch to gcc's -fstack-protector

_FORTIFY_SOURCE=2 compiles fail with error on newer gccs if
-O is not enabled.  Instead of risking optimization related issues,
switching to gcc -fstack-protect (since 4.1 or 2007) or
-fstack-protector-strong (since 4.9 or 2014).

Redhat/Fedora ships with -fstack-protector for all RPM's and
is switching to -fstack-protector-strong this year so should be
well tested.

cmake could stand to be improved and enable -fstack-protector-strong
for newer compilers.

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -68,7 +68,7 @@
 project(sox C)
 
 if(CMAKE_COMPILER_IS_GNUCC)
-	add_definitions(-D_FORTIFY_SOURCE=2 -Wall -W -Wmissing-prototypes -Wstrict-prototypes -pedantic -Wno-format -Wno-long-long)
+	add_definitions(-fstack-protector -Wall -W -Wmissing-prototypes -Wstrict-prototypes -pedantic -Wno-format -Wno-long-long)
 endif(CMAKE_COMPILER_IS_GNUCC)
 
 include(TestBigEndian)
--- a/configure.ac
+++ b/configure.ac
@@ -97,7 +97,13 @@
     gccver=`$CC -dumpversion`
     AC_MSG_RESULT($gccver)
 
-    CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=2 -Wall -W -Wmissing-prototypes -Wstrict-prototypes -pedantic"
+    CFLAGS="$CFLAGS -Wall -W -Wmissing-prototypes -Wstrict-prototypes -pedantic"
+    AS_VERSION_COMPARE([$gccver], [4.1],,
+		       [CFLAGS="$CFLAGS -fstack-protector"],
+		       [AS_VERSION_COMPARE([$gccver], [4.9],,
+					  [CFLAGS="$CFLAGS -fstack-protector-strong"],
+					  [CFLAGS="$CFLAGS -fstack-protector-strong"])])
+
     AS_VERSION_COMPARE([$gccver], [4.3],
        [WARN_CFLAGS="-Wconversion"],
        [WARN_CFLAGS="-Wtraditional-conversion"],