]> granicus.if.org Git - handbrake/commitdiff
build: Add --enable-hardening flag to enable stack protection and enhanced buffer...
authorNomis101 <Nomis101@web.de>
Mon, 22 Apr 2019 18:31:28 +0000 (20:31 +0200)
committerBradley Sepos <bradley@bradleysepos.com>
Wed, 19 Jun 2019 18:10:45 +0000 (14:10 -0400)
Prints the hardening status on global init to the log. Closes #2027. Was #2040.

libhb/hb.c
libhb/project.h.m4
macosx/HBOutputPanelController.m
make/configure.py
make/include/gcc.defs

index 9b3cea1667bd419f2c3b4a95ad54a5b32f2dbd09..720a7585dbd794348687222a5f7b0399c218d590 100644 (file)
@@ -1652,6 +1652,11 @@ int hb_global_init_no_hardware()
 
 int hb_global_init()
 {
+    /* Print hardening status on global init */
+#ifdef HB_PROJECT_HOST_HARDEN
+    hb_log( "Compile-time hardening features are enabled" );
+#endif
+
     int result = 0;
 
     result = hb_platform_init();
index ff727e006a5f8a55d97ce74068908b1bb1e60277..2ce9fac681f5a6325f8dd7a5c7804e8073ad86b1 100644 (file)
@@ -38,6 +38,7 @@ dnl
 <<#>>define HB_PROJECT_HOST_RELEASE              "__HOST_release"
 <<#>>define HB_PROJECT_HOST_TITLE                "__HOST_title"
 <<#>>define HB_PROJECT_HOST_ARCH                 "__HOST_arch"
+<<#>>define HB_PROJECT_HOST_HARDEN               __HOST_harden
 
 <<#>>define HB_PROJECT_FEATURE_ASM               __FEATURE_asm
 <<#>>define HB_PROJECT_FEATURE_FDK_AAC           __FEATURE_fdk_aac
index 5da8ebaf9d227a3fb9e294f0580e1096849936d2..83b5b22681200c8b978bce3bb1dfa00aa48255ad 100644 (file)
@@ -9,6 +9,7 @@
 #import "HBOutputRedirect.h"
 #import "HBOutputFileWriter.h"
 #import "HBUtilities.h"
+#import "project.h"
 
 /// Maximum amount of characters that can be shown in the view.
 #define TextStorageUpperSizeLimit 125000
         NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
         NSString *versionStringFull = [NSString stringWithFormat:@"Handbrake Version: %@  (%@)", infoDict[@"CFBundleShortVersionString"], infoDict[@"CFBundleVersion"]];
         [HBUtilities writeToActivityLog: "%s", versionStringFull.UTF8String];
+        
+        // Lets also report the hardening status to the activity log, if enabled
+#if HB_PROJECT_HOST_HARDEN == 1
+        [HBUtilities writeToActivityLog:"Compile-time hardening features are enabled"];
+#endif
     }
     return self;
 }
index b3dcc205e0aa09480f48ffd8477772263a9085a5..eb12c34c9d4cbc131232da38d949fd80db70ed8e 100644 (file)
@@ -686,7 +686,7 @@ class ArchAction( Action ):
 
             ## special cases in that powerpc does not match gcc -arch value
             ## which we like to use; so it has to be removed.
-            ## note: we don't know if apple will release Ssnow Leopad/ppc64 yet; just a guess.
+            ## note: we don't know if apple will release Snow Leopard/ppc64 yet; just a guess.
             if 'powerpc' in self.mode:
                 del self.mode['powerpc']
                 self.mode.mode = 'ppc'
@@ -1399,6 +1399,8 @@ def createCLI( cross = None ):
     arch.mode.cli_add_argument( grp, '--arch' )
     grp.add_argument( '--cross', default=None, action='store', metavar='SPEC',
         help='specify GCC cross-compilation spec' )
+    grp.add_argument( '--enable-hardening', dest="enable_host_harden", default=None, action='store_true',
+        help='enable buffer overflow protection' )
     cli.add_argument_group( grp )
 
     ## add Xcode options
@@ -1948,6 +1950,7 @@ int main()
         doc.add( 'HOST.cross.prefix', '' )
 
     doc.add( 'HOST.arch',   arch.mode.mode )
+    doc.add( 'HOST.harden', int( options.enable_host_harden != None))
 
     doc.addBlank()
     doc.add( 'SRC',     cfg.src_final )
index 7a67f4b2f2e280ee104257aba8984291ca7a0611..bd2d82dd0d732559f9862a4f81f56b0c752efd5f 100644 (file)
@@ -86,6 +86,13 @@ GCC.args.extra.hpp_o   =
 GCC.args.extra.cpp_o   =
 GCC.args.extra.dylib++ = $(LDFLAGS)
 GCC.args.extra.exe++   = $(LDFLAGS)
+# If hardening is enabled -D_FORTIFY_SOURCE=2 adds compile-time protection and run-time
+# checking against static sized buffer overflow flaws. -fstack-protector-strong enables
+# stack canaries to detect stack buffer overflows (stack overwrites).
+ifeq (1,$(HOST.harden))
+    GCC.args.extra     += $(CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -fstack-protector-strong -D_FORTIFY_SOURCE=2
+    GCC.args.extra.exe += -fstack-protector-strong
+endif
 
 ###############################################################################