[vlc-commits] [Git][videolan/vlc][master] meson: add stack protection option

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Jan 31 09:09:27 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
6b1f7dc2 by Steve Lhomme at 2023-01-31T08:53:16+00:00
meson: add stack protection option

- - - - -


2 changed files:

- meson.build
- meson_options.txt


Changes:

=====================================
meson.build
=====================================
@@ -791,6 +791,33 @@ add_project_arguments(
     cc.get_supported_arguments('-fvisibility=hidden'),
     language: ['c'])
 
+# Stack smashing protection (default enabled for optimized builds)
+if (get_option('ssp')
+    .disable_auto_if(get_option('optimization') == '0')
+    .allowed())
+    add_project_arguments(
+        cc.get_supported_arguments('-fstack-protector-strong'),
+        language: ['c', 'cpp'])
+
+    if host_system == 'windows'
+        # Win32 requires linking to ssp for stack-protection
+ssp_test = '''
+#include <stdio.h>
+
+int main(void) {
+    char buf[100];
+    fgets(buf, sizeof(buf), stdin);
+    return 0;
+}
+'''
+        # Check if linker supports -lssp
+        if cc.links(ssp_test, args: ['-fstack-protector-strong', '-lssp'],
+                    name: 'linker supports stack protectors')
+            add_project_link_arguments('-lssp', language: ['c', 'cpp'])
+        endif
+    endif
+endif
+
 # Check if linker supports -Bsymbolic
 symbolic_linkargs = []
 if cc.has_link_argument('-Wl,-Bsymbolic')
@@ -987,4 +1014,4 @@ subdir('modules')
 warning('''
     The Meson build system of VLC is currently EXPERIMENTAL and INCOMPLETE.
     Testing and reporting or contributing missing plugins and features is welcome!
-''')
\ No newline at end of file
+''')


=====================================
meson_options.txt
=====================================
@@ -45,6 +45,11 @@ option('branch_protection',
     value : 'auto',
     description : 'AArch64 branch protection')
 
+option('ssp',
+    type : 'feature',
+    value : 'auto',
+    description : 'Stack smashing protection')
+
 option('winstore_app',
     type : 'boolean',
     value : 'false',



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6b1f7dc26554e92351f9513359332664358eb540

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6b1f7dc26554e92351f9513359332664358eb540
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list