Skip to content

Commit 793f22f

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. Do that by switching from zend_hash_destroy to zend_array_destroy, which should also be faster for freeing members due to inlining of i_zval_ptr_dtor.
1 parent b389846 commit 793f22f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

ext/mbstring/mbstring.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,7 @@ PHP_RSHUTDOWN_FUNCTION(mbstring)
11591159

11601160
if (MBSTRG(all_encodings_list)) {
11611161
GC_DELREF(MBSTRG(all_encodings_list));
1162-
zend_hash_destroy(MBSTRG(all_encodings_list));
1163-
efree(MBSTRG(all_encodings_list));
1162+
zend_array_destroy(MBSTRG(all_encodings_list));
11641163
MBSTRG(all_encodings_list) = NULL;
11651164
}
11661165

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)