Skip to content

Commit 4c9375e

Browse files
nielsdostodeveni
authored andcommitted
Fix GH-10187: Segfault in stripslashes() with arm64
Closes GH-10188 Co-authored-by: todeveni <toni.viemero@iki.fi> Signed-off-by: George Peter Banyard <girgias@php.net>
1 parent c2b0be5 commit 4c9375e

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ PHP NEWS
3434
- Posix:
3535
. Fix memory leak in posix_ttyname() (girgias)
3636

37+
- Standard:
38+
. Fix GH-10187 (Segfault in stripslashes() with arm64). (nielsdos)
39+
3740
- TSRM:
3841
. Fixed Windows shmget() wrt. IPC_PRIVATE. (Tyson Andre)
3942

ext/standard/string.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3988,19 +3988,23 @@ static zend_always_inline char *php_stripslashes_impl(const char *str, char *out
39883988
quad_word q;
39893989
vst1q_u8(q.mem, vceqq_u8(x, vdupq_n_u8('\\')));
39903990
if (q.dw[0] | q.dw[1]) {
3991-
int i = 0;
3992-
for (; i < 16; i++) {
3991+
unsigned int i = 0;
3992+
while (i < 16) {
39933993
if (q.mem[i] == 0) {
39943994
*out++ = str[i];
3995+
i++;
39953996
continue;
39963997
}
39973998

39983999
i++; /* skip the slash */
3999-
char s = str[i];
4000-
if (s == '0')
4001-
*out++ = '\0';
4002-
else
4003-
*out++ = s; /* preserve the next character */
4000+
if (i < len) {
4001+
char s = str[i];
4002+
if (s == '0')
4003+
*out++ = '\0';
4004+
else
4005+
*out++ = s; /* preserve the next character */
4006+
i++;
4007+
}
40044008
}
40054009
str += i;
40064010
len -= i;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
GH-10187 (Segfault in stripslashes() with arm64)
3+
--FILE--
4+
<?php
5+
var_dump(stripslashes("1234567890abcde\\"));
6+
?>
7+
--EXPECT--
8+
string(15) "1234567890abcde"

0 commit comments

Comments
 (0)