17from libomputils
import ScriptError, error, print_error_line, execute_command
21 """Returns true if stack of library file is executable"""
22 r = execute_command([
"readelf",
"-l",
"-W", library])
24 error(
"{} failed".format(r.command))
26 for line
in r.stdout.split(os.linesep):
27 if re.search(
"STACK", line):
28 stack_lines.append(line.strip())
30 error(
"{}: Not stack segment found".format(library))
31 if len(stack_lines) > 1:
32 error(
"{}: More than one stack segment found".format(library))
35 r"((GNU_)?STACK)\s+({0})\s+({0})\s+({0})\s+({0})\s+({0})"
36 " ([R ][W ][E ])".format(h),
40 error(
"{}: Cannot parse stack segment line".format(library))
49 parser = argparse.ArgumentParser(
50 description=
"Check library does not have" " executable stack"
52 parser.add_argument(
"library", help=
"The library file to check")
53 commandArgs = parser.parse_args()
55 error(
"{}: Stack is executable".format(commandArgs.library))
58if __name__ ==
"__main__":
61 except ScriptError
as e:
62 print_error_line(str(e))
def is_stack_executable_readelf(library)