3 Test script for security-check.py 5 from __future__
import division,print_function
11 with open(filename,
'w')
as f:
16 printf("the quick brown fox jumps over the lazy god\\n"); 22 subprocess.check_call([cc,source,
'-o',executable] + options)
23 p = subprocess.Popen([
'./security-check.py',executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
24 (stdout, stderr) = p.communicate()
25 return (p.returncode, stdout.rstrip())
34 self.assertEqual(
call_security_check(cc, source, executable, [
'-Wl,-zexecstack',
'-fno-stack-protector',
'-Wl,-znorelro']),
35 (1, executable+
': failed PIE NX RELRO Canary'))
36 self.assertEqual(
call_security_check(cc, source, executable, [
'-Wl,-znoexecstack',
'-fno-stack-protector',
'-Wl,-znorelro']),
37 (1, executable+
': failed PIE RELRO Canary'))
38 self.assertEqual(
call_security_check(cc, source, executable, [
'-Wl,-znoexecstack',
'-fstack-protector-all',
'-Wl,-znorelro']),
39 (1, executable+
': failed PIE RELRO'))
40 self.assertEqual(
call_security_check(cc, source, executable, [
'-Wl,-znoexecstack',
'-fstack-protector-all',
'-Wl,-znorelro',
'-pie',
'-fPIE']),
41 (1, executable+
': failed RELRO'))
42 self.assertEqual(
call_security_check(cc, source, executable, [
'-Wl,-znoexecstack',
'-fstack-protector-all',
'-Wl,-zrelro',
'-Wl,-z,now',
'-pie',
'-fPIE']),
47 executable =
'test1.exe' 48 cc =
'i686-w64-mingw32-gcc' 52 (1, executable+
': failed PIE NX'))
54 (1, executable+
': failed PIE'))
55 self.assertEqual(
call_security_check(cc, source, executable, [
'-Wl,--nxcompat',
'-Wl,--dynamicbase']),
58 if __name__ ==
'__main__':
def call_security_check(cc, source, executable, options)
def write_testcode(filename)