|
|
|
@ -5,6 +5,7 @@
|
|
|
|
|
'''
|
|
|
|
|
Test script for security-check.py
|
|
|
|
|
'''
|
|
|
|
|
import os
|
|
|
|
|
import subprocess
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
@ -19,6 +20,10 @@ def write_testcode(filename):
|
|
|
|
|
}
|
|
|
|
|
''')
|
|
|
|
|
|
|
|
|
|
def clean_files(source, executable):
|
|
|
|
|
os.remove(source)
|
|
|
|
|
os.remove(executable)
|
|
|
|
|
|
|
|
|
|
def call_security_check(cc, source, executable, options):
|
|
|
|
|
subprocess.run([cc,source,'-o',executable] + options, check=True)
|
|
|
|
|
p = subprocess.run(['./contrib/devtools/security-check.py',executable], stdout=subprocess.PIPE, universal_newlines=True)
|
|
|
|
@ -44,6 +49,8 @@ class TestSecurityChecks(unittest.TestCase):
|
|
|
|
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-znoexecstack','-fstack-protector-all','-Wl,-zrelro','-Wl,-z,now','-pie','-fPIE', '-Wl,-z,separate-code']),
|
|
|
|
|
(0, ''))
|
|
|
|
|
|
|
|
|
|
clean_files(source, executable)
|
|
|
|
|
|
|
|
|
|
def test_PE(self):
|
|
|
|
|
source = 'test1.c'
|
|
|
|
|
executable = 'test1.exe'
|
|
|
|
@ -61,6 +68,8 @@ class TestSecurityChecks(unittest.TestCase):
|
|
|
|
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,--nxcompat','-Wl,--dynamicbase','-Wl,--high-entropy-va','-pie','-fPIE']),
|
|
|
|
|
(0, ''))
|
|
|
|
|
|
|
|
|
|
clean_files(source, executable)
|
|
|
|
|
|
|
|
|
|
def test_MACHO(self):
|
|
|
|
|
source = 'test1.c'
|
|
|
|
|
executable = 'test1'
|
|
|
|
@ -80,6 +89,8 @@ class TestSecurityChecks(unittest.TestCase):
|
|
|
|
|
self.assertEqual(call_security_check(cc, source, executable, ['-Wl,-pie','-Wl,-bind_at_load','-fstack-protector-all']),
|
|
|
|
|
(0, ''))
|
|
|
|
|
|
|
|
|
|
clean_files(source, executable)
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
|
|