Skip to content

Commit

Permalink
Fix for overwritten env when parsing core file (#1014)
Browse files Browse the repository at this point in the history
* Fix for overwritten env when parsing core file

* warn_once message when dealing with overwritten pointer to env variable in core file
  • Loading branch information
cgsecurity authored and zachriggle committed Sep 6, 2017
1 parent 6263a34 commit c438893
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pwnlib/elf/corefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def __init__(self, *a, **kw):
log.warn('Could not find the stack!')
self.stack = None

with context.local(bytes=self.bytes, log_level='error'):
with context.local(bytes=self.bytes, log_level='warn'):
try:
self._parse_stack()
except ValueError:
Expand Down Expand Up @@ -826,6 +826,10 @@ def _parse_stack(self):
# find a pointer to this address, followed by a NULL.
last_env_addr = address + 1
p_last_env_addr = stack.find(pack(last_env_addr), None, last_env_addr)
if p_last_env_addr < 0:
# Something weird is happening. Just don't touch it.
log.warn_once("Found bad environment at %#x", last_env_addr)
return

# Sanity check that we did correctly find the envp NULL terminator.
envp_nullterm = p_last_env_addr+context.bytes
Expand Down

0 comments on commit c438893

Please sign in to comment.