Skip to content

Commit

Permalink
vs2010: Fix implementation of strcasestr
Browse files Browse the repository at this point in the history
A haystack which is shorter than the needle resulted in negative value
for length_haystack which was forced to a very large unsigned value.

The resulting buffer overflow while reading the haystack would crash
text2image when it was called with a short font name.

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Aug 31, 2016
1 parent 2660647 commit 4708ea3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions vs2010/port/strcasestr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ char *strcasestr(const char *haystack, const char *needle) {
return NULL;

length_needle = strlen(needle);
length_haystack = strlen(haystack) - length_needle + 1;
length_haystack = strlen(haystack);

for (i = 0; i < length_haystack; i++)
if (length_haystack < length_needle)
return NULL;

length_haystack -= length_needle;

for (i = 0; i <= length_haystack; i++)
{
size_t j;

Expand All @@ -71,4 +76,4 @@ char *strcasestr(const char *haystack, const char *needle) {
}

return NULL;
}
}

0 comments on commit 4708ea3

Please sign in to comment.