Skip to content

Commit d3aeb8a

Browse files
committed
Merge branch 'PHP-5.4.40' into PHP-5.4
* PHP-5.4.40: update NEWS Fix bug #69441 (Buffer Overflow when parsing tar/zip/phar in phar_set_inode) fix memory leak & add test Fix tests fix CVE num Fix bug #69337 (php_stream_url_wrap_http_ex() type-confusion vulnerability) Fix test Additional fix for bug #69324 More fixes for bug #69152 Fixed bug #69353 (Missing null byte checks for paths in various PHP extensions) Fixed bug #69324 (Buffer Over-read in unserialize when parsing Phar) Fixed bug #69316 (Use-after-free in php_curl related to CURLOPT_FILE/_INFILE/_WRITEHEADER) Fix bug #68486 and bug #69218 (segfault in apache2handler with apache 2.4) Fix bug #68819 (Fileinfo on specific file causes spurious OOM and/or segfault)
2 parents ae46d1c + d734e75 commit d3aeb8a

34 files changed

+382
-128
lines changed

NEWS

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,49 @@
11
PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3-
?? ??? 2015 PHP 5.4.40
3+
16 Apr 2015 PHP 5.4.40
4+
5+
- Apache2handler:
6+
. Fixed bug #69218 (potential remote code execution with apache 2.4
7+
apache2handler). (Gerrit Venema)
8+
9+
- Core:
10+
. Additional fix for bug #69152 (Type confusion vulnerability in
11+
exception::getTraceAsString). (Stas)
12+
. Fixed bug #69337 (php_stream_url_wrap_http_ex() type-confusion
13+
vulnerability). (Stas)
14+
. Fixed bug #69353 (Missing null byte checks for paths in various PHP
15+
extensions). (Stas)
16+
17+
- cURL:
18+
. Fixed bug #69316 (Use-after-free in php_curl related to
19+
CURLOPT_FILE/_INFILE/_WRITEHEADER). (Laruence)
420

521
- Ereg:
622
. Fixed bug #68740 (NULL Pointer Dereference). (Laruence)
723

24+
- Fileinfo:
25+
. Fixed bug #68819 (Fileinfo on specific file causes spurious OOM and/or
26+
segfault). (Anatol Belski)
27+
828
- GD:
929
. Fixed bug #68601 (buffer read overflow in gd_gif_in.c). (Remi)
1030

31+
- Phar:
32+
. Fixed bug #68901 (use after free). (bugreports at internot dot info)
33+
. Fixed bug #69324 (Buffer Over-read in unserialize when parsing Phar). (Stas)
34+
. Fixed bug #69441 (Buffer Overflow when parsing tar/zip/phar in
35+
phar_set_inode). (Stas)
36+
37+
- Postgres:
38+
. Fixed bug #68741 (Null pointer deference) (CVE-2015-1352). (Xinchen Hui)
39+
1140
- SOAP:
1241
. Fixed bug #69152 (Type Confusion Infoleak Vulnerability in unserialize()
1342
with SoapFault). (Dmitry)
1443

1544
- Sqlite3:
1645
. Fixed bug #66550 (SQLite prepared statement use-after-free). (Sean Heelan)
1746

18-
- Phar:
19-
. Fixed bug #68901 (use after free). (bugreports at internot dot info)
20-
21-
- Postgres:
22-
. Fixed bug #68741 (Null pointer deference) (CVE-2015-1352). (Xinchen Hui)
23-
2447
19 Mar 2015 PHP 5.4.39
2548

2649
- Core:

Zend/zend_exceptions.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,9 @@ ZEND_METHOD(exception, getTraceAsString)
591591
str = &res;
592592

593593
trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC);
594+
if(Z_TYPE_P(trace) != IS_ARRAY) {
595+
RETURN_FALSE;
596+
}
594597
zend_hash_apply_with_arguments(Z_ARRVAL_P(trace) TSRMLS_CC, (apply_func_args_t)_build_trace_string, 3, str, len, &num);
595598

596599
s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 7 + 1);

ext/curl/interface.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@ static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
10511051
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_WRITEFUNCTION");
10521052
length = -1;
10531053
} else if (retval_ptr) {
1054+
_php_curl_verify_handlers(ch, 1 TSRMLS_CC);
10541055
if (Z_TYPE_P(retval_ptr) != IS_LONG) {
10551056
convert_to_long_ex(&retval_ptr);
10561057
}
@@ -1124,6 +1125,7 @@ static size_t curl_progress(void *clientp, double dltotal, double dlnow, double
11241125
if (error == FAILURE) {
11251126
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call the CURLOPT_PROGRESSFUNCTION");
11261127
} else if (retval_ptr) {
1128+
_php_curl_verify_handlers(ch, 1 TSRMLS_CC);
11271129
if (Z_TYPE_P(retval_ptr) != IS_LONG) {
11281130
convert_to_long_ex(&retval_ptr);
11291131
}
@@ -1200,6 +1202,7 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
12001202
length = CURL_READFUNC_ABORT;
12011203
#endif
12021204
} else if (retval_ptr) {
1205+
_php_curl_verify_handlers(ch, 1 TSRMLS_CC);
12031206
if (Z_TYPE_P(retval_ptr) == IS_STRING) {
12041207
length = MIN((int) (size * nmemb), Z_STRLEN_P(retval_ptr));
12051208
memcpy(data, Z_STRVAL_P(retval_ptr), length);
@@ -1274,6 +1277,7 @@ static size_t curl_write_header(char *data, size_t size, size_t nmemb, void *ctx
12741277
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not call the CURLOPT_HEADERFUNCTION");
12751278
length = -1;
12761279
} else if (retval_ptr) {
1280+
_php_curl_verify_handlers(ch, 1 TSRMLS_CC);
12771281
if (Z_TYPE_P(retval_ptr) != IS_LONG) {
12781282
convert_to_long_ex(&retval_ptr);
12791283
}

ext/curl/tests/bug69316.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Bug #69316: Use-after-free in php_curl related to CURLOPT_FILE/_INFILE/_WRITEHEADER
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("curl")) exit("skip curl extension not loaded");
6+
if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER')) exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined");
7+
?>
8+
--FILE--
9+
<?php
10+
function hdr_callback($ch, $data) {
11+
// close the stream, causing the FILE structure to be free()'d
12+
if($GLOBALS['f_file']) {
13+
fclose($GLOBALS['f_file']); $GLOBALS['f_file'] = 0;
14+
15+
// cause an allocation of approx the same size as a FILE structure, size varies a bit depending on platform/libc
16+
$FILE_size = (PHP_INT_SIZE == 4 ? 0x160 : 0x238);
17+
curl_setopt($ch, CURLOPT_COOKIE, str_repeat("a", $FILE_size - 1));
18+
}
19+
return strlen($data);
20+
}
21+
$host = getenv('PHP_CURL_HTTP_REMOTE_SERVER');
22+
23+
$temp_file = dirname(__FILE__) . '/body.tmp';
24+
$url = "{$host}/get.php?test=getpost";
25+
$ch = curl_init();
26+
$f_file = fopen($temp_file, "w") or die("failed to open file\n");
27+
curl_setopt($ch, CURLOPT_BUFFERSIZE, 10);
28+
curl_setopt($ch, CURLOPT_HEADERFUNCTION, "hdr_callback");
29+
curl_setopt($ch, CURLOPT_FILE, $f_file);
30+
curl_setopt($ch, CURLOPT_URL, $url);
31+
curl_exec($ch);
32+
curl_close($ch);
33+
?>
34+
===DONE===
35+
--CLEAN--
36+
<?php
37+
unlink(dirname(__FILE__) . '/body.tmp');
38+
?>
39+
--EXPECTF--
40+
Warning: curl_exec(): CURLOPT_FILE resource has gone away, resetting to default in %s on line %d
41+
===DONE===

ext/dom/document.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,9 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int sourc
15801580
xmlInitParser();
15811581

15821582
if (mode == DOM_LOAD_FILE) {
1583+
if (CHECK_NULL_PATH(source, source_len)) {
1584+
return NULL;
1585+
}
15831586
char *file_dest = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN TSRMLS_CC);
15841587
if (file_dest) {
15851588
ctxt = xmlCreateFileParserCtxt(file_dest);
@@ -2168,7 +2171,7 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
21682171

21692172
id = getThis();
21702173

2171-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &source, &source_len, &options) == FAILURE) {
2174+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &source, &source_len, &options) == FAILURE) {
21722175
return;
21732176
}
21742177

ext/dom/tests/DOMDocument_loadHTMLfile_error2.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ assert.bail=true
1313
$doc = new DOMDocument();
1414
$result = $doc->loadHTMLFile("");
1515
assert('$result === false');
16+
$doc = new DOMDocument();
17+
$result = $doc->loadHTMLFile("text.html\0something");
18+
assert('$result === null');
1619
?>
1720
--EXPECTF--
1821
%r(PHP ){0,1}%rWarning: DOMDocument::loadHTMLFile(): Empty string supplied as input %s
22+
23+
%r(PHP ){0,1}%rWarning: DOMDocument::loadHTMLFile() expects parameter 1 to be a valid path, string given %s

ext/fileinfo/fileinfo.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,11 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
506506
RETVAL_FALSE;
507507
goto clean;
508508
}
509+
if (CHECK_NULL_PATH(buffer, buffer_len)) {
510+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid path");
511+
RETVAL_FALSE;
512+
goto clean;
513+
}
509514

510515
wrap = php_stream_locate_url_wrapper(buffer, &tmp2, 0 TSRMLS_CC);
511516

ext/fileinfo/libmagic/softmagic.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,9 @@ mcopy(struct magic_set *ms, union VALUETYPE *p, int type, int indir,
10371037
if (bytecnt > nbytes) {
10381038
bytecnt = nbytes;
10391039
}
1040+
if (offset > bytecnt) {
1041+
offset = bytecnt;
1042+
}
10401043
if (s == NULL) {
10411044
ms->search.s_len = 0;
10421045
ms->search.s = NULL;

ext/fileinfo/tests/bug68819_001.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #68819 Fileinfo on specific file causes spurious OOM and/or segfault, var 1
3+
--SKIPIF--
4+
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
8+
$string = <<<HERE
9+
----a-----'''---------a---------------a--------a-----a-----a---------a-----as-------a----a--a-------------a--as-----s---------------a---------a---a--s-a-----a-----------asy---------a-----a-----------a----s--------a-------------a-------a--------a----s------------a-----a----------------a----s-----------------\r\n-------------------a-------a-a-------a-----a----a----s----s--------a-----------------------a----a----s-------------a------------------s-------a----a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n-------------------a-------a-a-------a-----a----a----s----s--------a----------a----------------------a----a----s-------------a----------------------------s-------a----a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n------a-------a-a-------a-----a----a---a-----a-----------------------a----a---a-----a------------------s-------a----a---a-----a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s------\r\n-------------------a-------a-a-------a-----a----a---a-------a------------------------a----a---a-----''--a-------------------s-------a----a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n-------------------a-------a-a-------a-----a----a-------s-----a---a-------------------------a----a-------------a---a-------------------s-------a----a-------------a---a-----as-a--------------a-----a--s----s---------y------------a-----a-s---a-------''----a---s--a-''------''----s------------a-y----------------s------a-----y--a-s--a-s------s--a-s----------''----------------------------a---s--a----a---------a-s---a-s--------s--------a---------s--a-y-------------as----a----a-------------a------a---s--a-s------a--------a----s----y--as--a----a-s---------------a-----a--------------------------------------\r\n-------------------a-------a-a-------a-----a----a-----------s--------a-----------------------a----a--------------------a------------------s-------a----a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n-------------------a-------a-a-------a-----a----a-----------s--------a----------a----------------------a----a--------------------a------------------------------s-------a----a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n-------------------a-------a-a-------a-----a----a---a-----------------------a----a---a------------------s-------a----a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n-------------------a-------a-a-------a-----a----a---a----------a----------------------a----a---a------------------------------s-------a----a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n-----a-a-----------a-------a-a-------a-----a----a----a---s-----a-----------------------a----a----a---------a-----------------s-------a----a----a---------a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n-------------------a-------a-a-------a-----a----a--------a----a-----------------------a----a----------a----a------------------s-------a----a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n-----a-------------a-------a-a-------a-----a----a--------s-----a---a-------------------------a----a--------------a---a-------------------s-------------a---------------a----a---a---a-----as-a--------------a-----a--s----s---------y------------a-----a-s---a-------''----a---s--a-''------''----s------------a-y----------------s------a-----y--a-s--a-s------s--a-s----------''----------------------------a---s--a----a---------a-s---a-s--------s--------a---------s--a-y-------------as----a----a-------------a------a---s--a-s------a--------a----s----y--as--a----a-s---------------a-----a--------------------------------------\r\n-------------------a-------a-a-------a-----a----a----------------a-----------------------a----a----------------a------------------s-------a----a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n-------------------a-------a-a-------a-----a----a----------------a----------a----------------------a----a----------------a-----------------------------s-------a----a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n---a---------------a-------a-a-------a-----as------------------------a--a--s------------------a-s------------------------a-----s--a-----'''----------a-s---------------------------------------------a-----s--a-----------------a---------a---a--s-a-----a-----------asy---------a-----a-----------a----s----------------------a----s--a-------------a-------a--------a----s------------a-----a----------------a----s------------------\r\n-a-----------------a-------a-a-------a--y---------a------------------y---------a-----'''-------y------a-y--a-------------------------a---------a---a----------as-a---a--s-a-----a-----------asy---------a-----a-----------a----s--------a-------------a-------a--------a----s---------a-----a----------------a----s------------------\r\n-a-----------------a-------a-a-------a--y-------------a------------------y-------------a-----'''-------y----------a-y--a-------------------------a---------a---a----------as-a---a--s-a-----a-----------asy---------a-----a-----------a----s--------a-------------a-------a--------a----s---------a-----a----------------a----s------------------\r\n-------------------a-------a-a-------a--a----a-----a------------------a----a-----a-----'''----------a----s----a----a-------s---a------------------a-----------a--s-a-----a---------------------a------a----s-a-----a-------s-s-------a----s--------a-------------a-------a--------a----s---------a-----a----------------a----s------------------\r\n------aa-----------a-------a-a------------s-a--s---------a---a------------------------a------------a---a------------------s--------a------------a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n-------------------a-------a-a------------------------s-----s--a----a-----------------------------------------s--a----a------------------s---------------------------------s--a----a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s--------------a-----a----------a----------s--a----------s-----------------\r\n-------------------a-------a-a--------------s-a---a--------------------------a---a------------------s----------a---a------as---s-a--------------s-----a------a-y--a-------a-----a--a--------a----s--------a-------------a-------a--------a----s---------------a-----a----------a----------s--a----------s-----------------\r\nsay-------a------------s-----''------a----s--------a-------------a-\r\n
10+
HERE;
11+
12+
$finfo = new finfo();
13+
$type = $finfo->buffer($string);
14+
15+
var_dump($type);
16+
?>
17+
--EXPECT--
18+
string(60) "ASCII text, with very long lines, with CRLF line terminators"

ext/fileinfo/tests/bug68819_002.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #68819 Fileinfo on specific file causes spurious OOM and/or segfault, var 2
3+
--SKIPIF--
4+
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
8+
$string = '';
9+
10+
// These two in any order
11+
$string .= "\r\n";
12+
$string .= "''''";
13+
14+
// Total string length > 8192
15+
$string .= str_repeat(chr(rand(32, 127)), 8184);
16+
17+
// Ending in this string
18+
$string .= "say";
19+
20+
$finfo = new finfo();
21+
$type = $finfo->buffer($string);
22+
var_dump($type);
23+
24+
?>
25+
--EXPECT--
26+
string(60) "ASCII text, with very long lines, with CRLF line terminators"

0 commit comments

Comments
 (0)