Skip to content

Commit f6885a9

Browse files
committed
ext/intl: Fix use-after-free in grapheme_stripos ASCII fast-path
1 parent a760cf7 commit f6885a9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

ext/intl/grapheme/grapheme_string.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,15 @@ U_CFUNC PHP_FUNCTION(grapheme_stripos)
180180

181181
found = php_memnstr(haystack_dup + noffset, needle_dup, needle_len, haystack_dup + haystack_len);
182182

183-
efree(haystack_dup);
184183
efree(needle_dup);
185184

186185
if (found) {
187-
RETURN_LONG(found - haystack_dup);
186+
ret_pos = found - haystack_dup;
187+
efree(haystack_dup);
188+
RETURN_LONG(ret_pos);
188189
}
189-
190+
191+
efree(haystack_dup);
190192
/* if needle was ascii too, we are all done, otherwise we need to try using Unicode to see what we get */
191193
if ( grapheme_ascii_check((unsigned char *)needle, needle_len) >= 0 ) {
192194
RETURN_FALSE;

0 commit comments

Comments
 (0)