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