Skip to content

Commit

Permalink
Fix return value of search_find_text() when the match is out of bounds
Browse files Browse the repository at this point in the history
When performing a regular expression search on a range, and there is a
match past the end of the range, search_find_text() used to improperly
return the position of the match, but without filling the
Sci_TextToFind structure.  This lead to the calling code assume there
was a match, and maybe read the uninitialized fields in the
Sci_TextToFind structure, thus leading to undefined behavior.

So, fix search_find_text() so it properly returns -1 when there is a
match but it is outside the bounds.
  • Loading branch information
b4n committed Dec 10, 2012
1 parent 89d6b42 commit 83e7afc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/search.c
Expand Up @@ -1989,7 +1989,9 @@ gint search_find_text(ScintillaObject *sci, gint flags, struct Sci_TextToFind *t
pos = ttf->chrg.cpMin;
ret = find_regex(sci, pos, regex);

if (ret >= 0 && ret < ttf->chrg.cpMax)
if (ret >= ttf->chrg.cpMax)
ret = -1;
else if (ret >= 0)
{
ttf->chrgText.cpMin = regex_matches[0].start;
ttf->chrgText.cpMax = regex_matches[0].end;
Expand Down

0 comments on commit 83e7afc

Please sign in to comment.