Skip to content

Commit 25ec7eb

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: 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 07bda97 + 5c90f8e commit 25ec7eb

File tree

6 files changed

+115
-5
lines changed

6 files changed

+115
-5
lines changed

ext/mbstring/libmbfl/filters/mbfilter_big5.c

+2-2
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

+10
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

+1
Original file line numberDiff line numberDiff line change
@@ -2287,6 +2287,7 @@ static PHP_FUNCTION(session_create_id)
22872287
/* Detect collision and retry */
22882288
if (PS(mod)->s_validate_sid(&PS(mod_data), new_id) == FAILURE) {
22892289
zend_string_release_ex(new_id, 0);
2290+
new_id = NULL;
22902291
continue;
22912292
}
22922293
break;

ext/session/tests/bug79091.phpt

+67
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

+3-3
Original file line numberDiff line numberDiff line change
@@ -5164,7 +5164,7 @@ PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, uint8_t *stateptr, const
51645164
}
51655165

51665166
lc = '>';
5167-
if (is_xml && *(p -1) == '-') {
5167+
if (is_xml && p >= buf + 1 && *(p -1) == '-') {
51685168
break;
51695169
}
51705170
in_q = state = is_xml = 0;
@@ -5196,7 +5196,7 @@ PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, uint8_t *stateptr, const
51965196
goto reg_char_1;
51975197
case '!':
51985198
/* JavaScript & Other HTML scripting languages */
5199-
if (*(p-1) == '<') {
5199+
if (p >= buf + 1 && *(p-1) == '<') {
52005200
state = 3;
52015201
lc = c;
52025202
p++;
@@ -5206,7 +5206,7 @@ PHPAPI size_t php_strip_tags_ex(char *rbuf, size_t len, uint8_t *stateptr, const
52065206
}
52075207
break;
52085208
case '?':
5209-
if (*(p-1) == '<') {
5209+
if (p >= buf + 1 && *(p-1) == '<') {
52105210
br=0;
52115211
state = 2;
52125212
p++;

ext/standard/tests/file/bug79099.phpt

+32
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)