Skip to content

Commit

Permalink
Merge pull request #131 from tecknicaltom/master
Browse files Browse the repository at this point in the history
Use Popen as context mgr to ensure streams close
  • Loading branch information
Wenzel authored Jan 19, 2024
2 parents 82bb94f + 1fc568e commit 050a6f5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions checksec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ def find_library_full(name):
abi_type = mach_map.get(machine, "libc6")
# Note, we search libXXX.so.XXX, not just libXXX.so (!)
expr = re.compile(r"^\s+lib%s\.so.[^\s]+\s+\(%s.*=>\s+(.*)$" % (re.escape(name), abi_type))
p = subprocess.Popen(["ldconfig", "-N", "-p"], stdout=subprocess.PIPE)
result = None
for line in p.stdout:
res = expr.match(line.decode())
if res is None:
continue
if result is not None:
raise RuntimeError("Duplicate library found for %s" % name)
result = res.group(1)
if p.wait():
raise RuntimeError('"ldconfig -p" failed')
with subprocess.Popen(["ldconfig", "-N", "-p"], stdout=subprocess.PIPE) as p:
for line in p.stdout:
res = expr.match(line.decode())
if res is None:
continue
if result is not None:
raise RuntimeError("Duplicate library found for %s" % name)
result = res.group(1)
if p.wait():
raise RuntimeError('"ldconfig -p" failed')
if result is None:
raise RuntimeError("Library %s not found" % name)
return result
Expand Down

0 comments on commit 050a6f5

Please sign in to comment.