File tree 5 files changed +23
-26
lines changed
5 files changed +23
-26
lines changed Original file line number Diff line number Diff line change 2
2
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3
3
?? ??? ????, PHP 8.3.0beta2
4
4
5
+ - Core:
6
+ . Fixed oss-fuzz #60741 (Leak in open_basedir). (ilutov)
7
+
5
8
- FFI:
6
9
. Fix leaking definitions when using FFI::cdef()->new(...). (ilutov)
7
10
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ oss-fuzz #60741: Leak in open_basedir
3
+ --INI--
4
+ open_basedir="{TMP}"
5
+ --FILE--
6
+ <?php
7
+ ini_set ('open_basedir ' , ini_get ('open_basedir ' ));
8
+ ?>
9
+ --EXPECT--
Original file line number Diff line number Diff line change @@ -1271,29 +1271,11 @@ void zend_call_destructors(void) /* {{{ */
1271
1271
}
1272
1272
/* }}} */
1273
1273
1274
- static void zend_release_open_basedir (void )
1275
- {
1276
- /* Release custom open_basedir config, this needs to happen before ini shutdown */
1277
- if (PG (open_basedir )) {
1278
- zend_ini_entry * ini_entry = zend_hash_str_find_ptr (EG (ini_directives ), "open_basedir" , strlen ("open_basedir" ));
1279
- /* ini_entry->modified is unreliable, it might also be set when on_update has failed. */
1280
- if (ini_entry
1281
- && ini_entry -> modified
1282
- && ini_entry -> value != ini_entry -> orig_value ) {
1283
- efree (PG (open_basedir ));
1284
- PG (open_basedir ) = NULL ;
1285
- }
1286
- }
1287
- }
1288
-
1289
1274
ZEND_API void zend_deactivate (void ) /* {{{ */
1290
1275
{
1291
1276
/* we're no longer executing anything */
1292
1277
EG (current_execute_data ) = NULL ;
1293
1278
1294
- /* Needs to run before zend_ini_deactivate(). */
1295
- zend_release_open_basedir ();
1296
-
1297
1279
zend_try {
1298
1280
shutdown_scanner ();
1299
1281
} zend_end_try ();
Original file line number Diff line number Diff line change @@ -77,8 +77,12 @@ PHPAPI ZEND_INI_MH(OnUpdateBaseDir)
77
77
char * pathbuf , * ptr , * end ;
78
78
79
79
if (stage == PHP_INI_STAGE_STARTUP || stage == PHP_INI_STAGE_SHUTDOWN || stage == PHP_INI_STAGE_ACTIVATE || stage == PHP_INI_STAGE_DEACTIVATE ) {
80
+ if (PG (open_basedir_modified )) {
81
+ efree (* p );
82
+ }
80
83
/* We're in a PHP_INI_SYSTEM context, no restrictions */
81
84
* p = new_value ? ZSTR_VAL (new_value ) : NULL ;
85
+ PG (open_basedir_modified ) = false;
82
86
return SUCCESS ;
83
87
}
84
88
@@ -117,15 +121,13 @@ PHPAPI ZEND_INI_MH(OnUpdateBaseDir)
117
121
efree (pathbuf );
118
122
119
123
/* Everything checks out, set it */
120
- if (* p ) {
121
- /* Unfortunately entry->modified has already been set to true so we compare entry->value
122
- * against entry->orig_value. */
123
- if (entry -> modified && entry -> value != entry -> orig_value ) {
124
- efree (* p );
125
- }
126
- }
127
124
zend_string * tmp = smart_str_extract (& buf );
128
- * p = estrdup (ZSTR_VAL (tmp ));
125
+ char * result = estrdup (ZSTR_VAL (tmp ));
126
+ if (PG (open_basedir_modified )) {
127
+ efree (* p );
128
+ }
129
+ * p = result ;
130
+ PG (open_basedir_modified ) = true;
129
131
zend_string_release (tmp );
130
132
131
133
return SUCCESS ;
Original file line number Diff line number Diff line change @@ -80,6 +80,7 @@ struct _php_core_globals {
80
80
char * user_dir ;
81
81
char * include_path ;
82
82
char * open_basedir ;
83
+ bool open_basedir_modified ;
83
84
char * extension_dir ;
84
85
char * php_binary ;
85
86
char * sys_temp_dir ;
You can’t perform that action at this time.
0 commit comments