@@ -59,17 +59,22 @@ def test_ELF(self):
59
59
arch = get_arch (cxx , source , executable )
60
60
61
61
if arch == lief .ARCHITECTURES .X86 :
62
- pass_flags = ['-Wl,-znoexecstack' , '-Wl,-zrelro' , '-Wl,-z,now' , '-pie' , '-fPIE' , '-Wl,-z,separate-code' , '-fcf-protection=full' ]
62
+ pass_flags = ['-D_FORTIFY_SOURCE=3' , '- Wl,-znoexecstack' , '-Wl,-zrelro' , '-Wl,-z,now' , '-pie' , '-fPIE' , '-Wl,-z,separate-code' , '-fcf-protection=full' ]
63
63
self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-Wl,-zexecstack' ]), (1 , executable + ': failed NX' ))
64
64
self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-no-pie' ,'-fno-PIE' ]), (1 , executable + ': failed PIE' ))
65
65
self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-Wl,-znorelro' ]), (1 , executable + ': failed RELRO' ))
66
66
self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-Wl,-z,noseparate-code' ]), (1 , executable + ': failed SEPARATE_CODE' ))
67
67
self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-fcf-protection=none' ]), (1 , executable + ': failed CONTROL_FLOW' ))
68
+ self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-U_FORTIFY_SOURCE' ]), (1 , executable + ': failed FORTIFY' ))
68
69
self .assertEqual (call_security_check (cxx , source , executable , pass_flags ), (0 , '' ))
69
70
else :
70
- pass_flags = ['-Wl,-znoexecstack' , '-Wl,-zrelro' , '-Wl,-z,now' , '-pie' , '-fPIE' , '-Wl,-z,separate-code' ]
71
+ pass_flags = ['-D_FORTIFY_SOURCE=3' , '- Wl,-znoexecstack' , '-Wl,-zrelro' , '-Wl,-z,now' , '-pie' , '-fPIE' , '-Wl,-z,separate-code' ]
71
72
self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-Wl,-zexecstack' ]), (1 , executable + ': failed NX' ))
72
- self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-no-pie' ,'-fno-PIE' ]), (1 , executable + ': failed PIE' ))
73
+ # LIEF fails to parse RISC-V with no PIE correctly, and doesn't detect the fortified function,
74
+ # so skip this test for RISC-V (for now). See https://github.com/lief-project/LIEF/issues/1082.
75
+ if arch != lief .ARCHITECTURES .RISCV :
76
+ self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-no-pie' ,'-fno-PIE' ]), (1 , executable + ': failed PIE' ))
77
+ self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-U_FORTIFY_SOURCE' ]), (1 , executable + ': failed FORTIFY' ))
73
78
self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-Wl,-znorelro' ]), (1 , executable + ': failed RELRO' ))
74
79
self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-Wl,-z,noseparate-code' ]), (1 , executable + ': failed SEPARATE_CODE' ))
75
80
self .assertEqual (call_security_check (cxx , source , executable , pass_flags ), (0 , '' ))
0 commit comments