Skip to content

Commit e6c9b17

Browse files
committedDec 30, 2022
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix GH-10187: Segfault in stripslashes() with arm64 Fix memory leak in posix_ttyname()
2 parents 9faa3f1 + 4c9375e commit e6c9b17

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed
 

‎NEWS

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ PHP NEWS
2323
. Fix undefined behaviour in phpdbg_load_module_or_extension(). (nielsdos)
2424
. Fix NULL pointer dereference in phpdbg_create_conditional_breal(). (nielsdos)
2525

26+
- Posix:
27+
. Fix memory leak in posix_ttyname() (girgias)
28+
29+
- Standard:
30+
. Fix GH-10187 (Segfault in stripslashes() with arm64). (nielsdos)
31+
2632
05 Jan 2023, PHP 8.2.1
2733

2834
- Core:

‎ext/posix/posix.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -474,15 +474,15 @@ PHP_FUNCTION(posix_ttyname)
474474
efree(p);
475475
RETURN_FALSE;
476476
}
477-
RETURN_STRING(p);
477+
RETVAL_STRING(p);
478478
efree(p);
479479
#else
480480
if (NULL == (p = ttyname(fd))) {
481481
POSIX_G(last_error) = errno;
482482
RETURN_FALSE;
483483
}
484-
#endif
485484
RETURN_STRING(p);
485+
#endif
486486
}
487487
/* }}} */
488488

‎ext/standard/string.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -3990,19 +3990,23 @@ static zend_always_inline char *php_stripslashes_impl(const char *str, char *out
39903990
quad_word q;
39913991
vst1q_u8(q.mem, vceqq_u8(x, vdupq_n_u8('\\')));
39923992
if (q.dw[0] | q.dw[1]) {
3993-
int i = 0;
3994-
for (; i < 16; i++) {
3993+
unsigned int i = 0;
3994+
while (i < 16) {
39953995
if (q.mem[i] == 0) {
39963996
*out++ = str[i];
3997+
i++;
39973998
continue;
39983999
}
39994000

40004001
i++; /* skip the slash */
4001-
char s = str[i];
4002-
if (s == '0')
4003-
*out++ = '\0';
4004-
else
4005-
*out++ = s; /* preserve the next character */
4002+
if (i < len) {
4003+
char s = str[i];
4004+
if (s == '0')
4005+
*out++ = '\0';
4006+
else
4007+
*out++ = s; /* preserve the next character */
4008+
i++;
4009+
}
40064010
}
40074011
str += i;
40084012
len -= i;
+8
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)
Failed to load comments.