Skip to content

Commit e1e2089

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-17047: UAF on iconv filter failure
2 parents 912b13a + c192a34 commit e1e2089

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

ext/iconv/iconv.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,7 +2535,8 @@ static php_stream_filter_status_t php_iconv_stream_filter_do_filter(
25352535
if (php_iconv_stream_filter_append_bucket(self, stream, filter,
25362536
buckets_out, bucket->buf, bucket->buflen, &consumed,
25372537
php_stream_is_persistent(stream)) != SUCCESS) {
2538-
goto out_failure;
2538+
php_stream_bucket_delref(bucket);
2539+
return PSFS_ERR_FATAL;
25392540
}
25402541

25412542
php_stream_bucket_delref(bucket);
@@ -2545,7 +2546,7 @@ static php_stream_filter_status_t php_iconv_stream_filter_do_filter(
25452546
if (php_iconv_stream_filter_append_bucket(self, stream, filter,
25462547
buckets_out, NULL, 0, &consumed,
25472548
php_stream_is_persistent(stream)) != SUCCESS) {
2548-
goto out_failure;
2549+
return PSFS_ERR_FATAL;
25492550
}
25502551
}
25512552

@@ -2554,12 +2555,6 @@ static php_stream_filter_status_t php_iconv_stream_filter_do_filter(
25542555
}
25552556

25562557
return PSFS_PASS_ON;
2557-
2558-
out_failure:
2559-
if (bucket != NULL) {
2560-
php_stream_bucket_delref(bucket);
2561-
}
2562-
return PSFS_ERR_FATAL;
25632558
}
25642559
/* }}} */
25652560

ext/iconv/tests/gh17047.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-17047 (UAF on iconv filter failure)
3+
--EXTENSIONS--
4+
iconv
5+
--FILE--
6+
<?php
7+
$stream = fopen('php://temp', 'w+');
8+
stream_filter_append($stream, 'convert.iconv.UTF-16BE.UTF-8');
9+
stream_filter_append($stream, 'convert.iconv.UTF-16BE.UTF-16BE');
10+
fputs($stream, 'test');
11+
rewind($stream);
12+
var_dump(stream_get_contents($stream));
13+
fclose($stream);
14+
?>
15+
--EXPECTF--
16+
Warning: stream_get_contents(): iconv stream filter ("UTF-16BE"=>"UTF-16BE"): invalid multibyte sequence in %s on line %d
17+
string(0) ""

0 commit comments

Comments
 (0)