Skip to content

Commit 30570b6

Browse files
committed
Fix uaf of MBSTRG(all_encodings_list)
We need to remove the value from the GC buffer before freeing it. Otherwise shutdown will uaf when running the gc.
1 parent b389846 commit 30570b6

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

ext/mbstring/mbstring.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,7 @@ PHP_RSHUTDOWN_FUNCTION(mbstring)
11581158
MBSTRG(outconv_state) = 0;
11591159

11601160
if (MBSTRG(all_encodings_list)) {
1161+
GC_REMOVE_FROM_BUFFER(MBSTRG(all_encodings_list));
11611162
GC_DELREF(MBSTRG(all_encodings_list));
11621163
zend_hash_destroy(MBSTRG(all_encodings_list));
11631164
efree(MBSTRG(all_encodings_list));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Use-after-free of MBSTRG(all_encodings_list) on shutdown
3+
--EXTENSIONS--
4+
mbstring
5+
--FILE--
6+
<?php
7+
mb_list_encodings();
8+
?>
9+
--EXPECT--

0 commit comments

Comments
 (0)