Skip to content

Commit

Permalink
contrib: assume binary existence in sec/sym checks
Browse files Browse the repository at this point in the history
If the binaries don't exist, the Guix build has failed for some other
reason.

There's no need to check for unknown architectures, or executable
formats, as the only ones that could be built are those that we've
configured toolchains for in Guix.

We've also been doing this inconsistently across the two scripts.
  • Loading branch information
fanquake committed Jul 18, 2024
1 parent 51d8f43 commit 1bc9f64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
37 changes: 11 additions & 26 deletions contrib/devtools/security-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,31 +248,16 @@ def check_MACHO_BRANCH_PROTECTION(binary) -> bool:
if __name__ == '__main__':
retval: int = 0
for filename in sys.argv[1:]:
try:
binary = lief.parse(filename)
etype = binary.format
arch = binary.abstract.header.architecture
binary.concrete

if etype == lief.EXE_FORMATS.UNKNOWN:
print(f'{filename}: unknown executable format')
retval = 1
continue

if arch == lief.ARCHITECTURES.NONE:
print(f'{filename}: unknown architecture')
retval = 1
continue

failed: list[str] = []
for (name, func) in CHECKS[etype][arch]:
if not func(binary):
failed.append(name)
if failed:
print(f'{filename}: failed {" ".join(failed)}')
retval = 1
except IOError:
print(f'{filename}: cannot open')
binary = lief.parse(filename)
etype = binary.format
arch = binary.abstract.header.architecture
binary.concrete

failed: list[str] = []
for (name, func) in CHECKS[etype][arch]:
if not func(binary):
failed.append(name)
if failed:
print(f'{filename}: failed {" ".join(failed)}')
retval = 1
sys.exit(retval)

26 changes: 9 additions & 17 deletions contrib/devtools/symbol-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,14 @@ def check_ELF_ABI(binary) -> bool:
if __name__ == '__main__':
retval: int = 0
for filename in sys.argv[1:]:
try:
binary = lief.parse(filename)
etype = binary.format
if etype == lief.EXE_FORMATS.UNKNOWN:
print(f'{filename}: unknown executable format')
retval = 1
continue

failed: list[str] = []
for (name, func) in CHECKS[etype]:
if not func(binary):
failed.append(name)
if failed:
print(f'{filename}: failed {" ".join(failed)}')
retval = 1
except IOError:
print(f'{filename}: cannot open')
binary = lief.parse(filename)
etype = binary.format

failed: list[str] = []
for (name, func) in CHECKS[etype]:
if not func(binary):
failed.append(name)
if failed:
print(f'{filename}: failed {" ".join(failed)}')
retval = 1
sys.exit(retval)

0 comments on commit 1bc9f64

Please sign in to comment.