From a161e9012bcc89edd9a16cd244fd13b114ec3390 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:31:40 +0100 Subject: [PATCH 1/2] Fix GH-10187: Segfault in stripslashes() with arm64 --- ext/standard/string.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index 8a223b72f4e33..e171448f243e1 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -3988,19 +3988,23 @@ static zend_always_inline char *php_stripslashes_impl(const char *str, char *out quad_word q; vst1q_u8(q.mem, vceqq_u8(x, vdupq_n_u8('\\'))); if (q.dw[0] | q.dw[1]) { - int i = 0; - for (; i < 16; i++) { + unsigned int i = 0; + while (i < 16) { if (q.mem[i] == 0) { *out++ = str[i]; + i++; continue; } i++; /* skip the slash */ - char s = str[i]; - if (s == '0') - *out++ = '\0'; - else - *out++ = s; /* preserve the next character */ + if (i < len) { + char s = str[i]; + if (s == '0') + *out++ = '\0'; + else + *out++ = s; /* preserve the next character */ + i++; + } } str += i; len -= i; From aecd406d1391820e46a93199ee1fb27280b6fba9 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 30 Dec 2022 14:37:29 +0100 Subject: [PATCH 2/2] Add a regression test for GH-10187 Co-authored-by: todeveni --- ext/standard/tests/strings/gh10187.phpt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 ext/standard/tests/strings/gh10187.phpt diff --git a/ext/standard/tests/strings/gh10187.phpt b/ext/standard/tests/strings/gh10187.phpt new file mode 100644 index 0000000000000..b42c95e591ed0 --- /dev/null +++ b/ext/standard/tests/strings/gh10187.phpt @@ -0,0 +1,8 @@ +--TEST-- +GH-10187 (Segfault in stripslashes() with arm64) +--FILE-- + +--EXPECT-- +string(15) "1234567890abcde"