@@ -59,17 +59,22 @@ def test_ELF(self):
5959 arch = get_arch (cxx , source , executable )
6060
6161 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' ]
6363 self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-Wl,-zexecstack' ]), (1 , executable + ': failed NX' ))
6464 self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-no-pie' ,'-fno-PIE' ]), (1 , executable + ': failed PIE' ))
6565 self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-Wl,-znorelro' ]), (1 , executable + ': failed RELRO' ))
6666 self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-Wl,-z,noseparate-code' ]), (1 , executable + ': failed SEPARATE_CODE' ))
6767 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' ))
6869 self .assertEqual (call_security_check (cxx , source , executable , pass_flags ), (0 , '' ))
6970 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' ]
7172 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' ))
7378 self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-Wl,-znorelro' ]), (1 , executable + ': failed RELRO' ))
7479 self .assertEqual (call_security_check (cxx , source , executable , pass_flags + ['-Wl,-z,noseparate-code' ]), (1 , executable + ': failed SEPARATE_CODE' ))
7580 self .assertEqual (call_security_check (cxx , source , executable , pass_flags ), (0 , '' ))
0 commit comments