Resolve the situation where the function name is bytes (#2367)

fix error:
 if function.name.endswith('_chk'):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: endswith first arg must be bytes or a tuple of bytes, not str

Co-authored-by: Ajin Abraham <[email protected]>
This commit is contained in:
ohyeah521
2024-03-24 14:56:26 -07:00
committed by GitHub
co-authored by Ajin Abraham
parent ccfedc0e45
commit 6bce5a25b4
@@ -290,7 +290,14 @@ class ELFChecksec:
def fortify(self):
fortified_funcs = []
for function in self.elf.symbols:
if function.name.endswith('_chk'):
if isinstance(function.name, bytes):
try:
function_name = function.name.decode('utf-8')
except UnicodeDecodeError:
function_name = function.name.decode('utf-8', 'replace')
else:
function_name = function.name
if function_name.endswith('_chk'):
fortified_funcs.append(function.name)
return fortified_funcs