Skip to content

Commit

Permalink
Strchr: Ensure that the string is long enough to include the found ch…
Browse files Browse the repository at this point in the history
…aracter (angr#3251)

* Strchr: Ensure that the string is long enough to include the found character

* strchr: Fix search for NULL byte

* strchr: Push the handling of NULL into the constraint

Co-authored-by: Edward J. Schwartz <[email protected]>
  • Loading branch information
edmcman and sei-eschwartz authored Mar 30, 2022
1 parent dc0b2df commit 884fb07
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions angr/procedures/libc/strchr.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ def run(self, s_addr, c_int, s_strlen=None):
a = a.annotate(MultiwriteAnnotation())
self.state.add_constraints(*c)

# If we found the character we are looking for, we need to
# ensure that the string length is long enough to include
# the character!
chrpos = a - s_addr
self.state.add_constraints(self.state.solver.If(a != 0,
chrpos <= s_strlen.ret_expr,
True))

return a
#self.state.add_constraints(self.state.solver.ULT(a - s_addr, s_strlen.ret_expr))
#self.max_chr_index = max(i)
Expand Down

0 comments on commit 884fb07

Please sign in to comment.