Skip to content

Commit a29c793

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Update NEWS Fix bug #79037 (global buffer-overflow in `mbfl_filt_conv_big5_wchar`) Fix #79099: OOB read in php_strip_tags_ex Fix #79091: heap use-after-free in session_create_id()
2 parents 7438046 + 25ec7eb commit a29c793

File tree

6 files changed

+115
-5
lines changed

6 files changed

+115
-5
lines changed

ext/mbstring/libmbfl/filters/mbfilter_big5.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ static unsigned short cp950_pua_tbl[][4] = {
145145
static inline int is_in_cp950_pua(int c1, int c) {
146146
if ((c1 >= 0xfa && c1 <= 0xfe) || (c1 >= 0x8e && c1 <= 0xa0) ||
147147
(c1 >= 0x81 && c1 <= 0x8d) || (c1 >= 0xc7 && c1 <= 0xc8)) {
148-
return (c > 0x39 && c < 0x7f) || (c > 0xa0 && c < 0xff);
148+
return (c >=0x40 && c <= 0x7e) || (c >= 0xa1 && c <= 0xfe);
149149
}
150150
if (c1 == 0xc6) {
151-
return c > 0xa0 && c < 0xff;
151+
return c >= 0xa1 && c <= 0xfe;
152152
}
153153
return 0;
154154
}

ext/mbstring/tests/bug79037.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #79037: global buffer-overflow in `mbfl_filt_conv_big5_wchar`
3+
--FILE--
4+
<?php
5+
6+
var_dump(mb_convert_encoding("\x81\x3a", "UTF-8", "CP950"));
7+
8+
?>
9+
--EXPECT--
10+
string(1) "?"

ext/session/session.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,7 @@ static PHP_FUNCTION(session_create_id)
22962296
/* Detect collision and retry */
22972297
if (PS(mod)->s_validate_sid(&PS(mod_data), new_id) == FAILURE) {
22982298
zend_string_release_ex(new_id, 0);
2299+
new_id = NULL;
22992300
continue;
23002301
}
23012302
break;

ext/session/tests/bug79091.phpt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
--TEST--
2+
Bug #79091 (heap use-after-free in session_create_id())
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('session')) die('skip session extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
class MySessionHandler implements SessionHandlerInterface, SessionIdInterface, SessionUpdateTimestampHandlerInterface
10+
{
11+
public function close()
12+
{
13+
return true;
14+
}
15+
16+
public function destroy($session_id)
17+
{
18+
return true;
19+
}
20+
21+
public function gc($maxlifetime)
22+
{
23+
return true;
24+
}
25+
26+
public function open($save_path, $session_name)
27+
{
28+
return true;
29+
}
30+
31+
public function read($session_id)
32+
{
33+
return '';
34+
}
35+
36+
public function write($session_id, $session_data)
37+
{
38+
return true;
39+
}
40+
41+
public function create_sid()
42+
{
43+
return uniqid();
44+
}
45+
46+
public function updateTimestamp($key, $val)
47+
{
48+
return true;
49+
}
50+
51+
public function validateId($key)
52+
{
53+
return false;
54+
}
55+
}
56+
57+
ob_start();
58+
var_dump(session_set_save_handler(new MySessionHandler()));
59+
var_dump(session_start());
60+
ob_flush();
61+
session_create_id();
62+
?>
63+
--EXPECTF--
64+
bool(true)
65+
bool(true)
66+
67+
Warning: session_create_id(): Failed to create new ID in %s on line %d

ext/standard/string.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5278,7 +5278,7 @@ PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, uint8_t *stateptr, const
52785278
}
52795279

52805280
lc = '>';
5281-
if (is_xml && *(p -1) == '-') {
5281+
if (is_xml && p >= buf + 1 && *(p -1) == '-') {
52825282
break;
52835283
}
52845284
in_q = state = is_xml = 0;
@@ -5310,7 +5310,7 @@ PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, uint8_t *stateptr, const
53105310
goto reg_char_1;
53115311
case '!':
53125312
/* JavaScript & Other HTML scripting languages */
5313-
if (*(p-1) == '<') {
5313+
if (p >= buf + 1 && *(p-1) == '<') {
53145314
state = 3;
53155315
lc = c;
53165316
p++;
@@ -5320,7 +5320,7 @@ PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, uint8_t *stateptr, const
53205320
}
53215321
break;
53225322
case '?':
5323-
if (*(p-1) == '<') {
5323+
if (p >= buf + 1 && *(p-1) == '<') {
53245324
br=0;
53255325
state = 2;
53265326
p++;

ext/standard/tests/file/bug79099.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Bug #79099 (OOB read in php_strip_tags_ex)
3+
--FILE--
4+
<?php
5+
$stream = fopen('php://memory', 'w+');
6+
fputs($stream, "<?\n\"\n");
7+
rewind($stream);
8+
var_dump(@fgetss($stream));
9+
var_dump(@fgetss($stream));
10+
fclose($stream);
11+
12+
$stream = fopen('php://memory', 'w+');
13+
fputs($stream, "<\0\n!\n");
14+
rewind($stream);
15+
var_dump(@fgetss($stream));
16+
var_dump(@fgetss($stream));
17+
fclose($stream);
18+
19+
$stream = fopen('php://memory', 'w+');
20+
fputs($stream, "<\0\n?\n");
21+
rewind($stream);
22+
var_dump(@fgetss($stream));
23+
var_dump(@fgetss($stream));
24+
fclose($stream);
25+
?>
26+
--EXPECT--
27+
string(0) ""
28+
string(0) ""
29+
string(0) ""
30+
string(0) ""
31+
string(0) ""
32+
string(0) ""

0 commit comments

Comments
 (0)