Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open file not destroy or crash in Yaf_Config_Ini, PHP 8.1 or later #587

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions configs/yaf_config_ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static zval* yaf_config_ini_get(yaf_config_object *conf, zend_string *name) /* {
char *seg, *delim;
size_t len;
HashTable *target;

if (conf->config == NULL) {
return NULL;
}
Expand Down Expand Up @@ -298,7 +298,7 @@ static void yaf_config_ini_parser_cb(zval *key, zval *value, zval *index, int ca
YAF_CONFIG_PARSER_FLAG() = YAF_CONFIG_INI_PARSING_END;
return;
}

p = Z_STRVAL_P(key);
l = Z_STRLEN_P(key);

Expand Down Expand Up @@ -387,6 +387,9 @@ int yaf_config_ini_init(yaf_config_object *conf, zval *filename, zend_string *se
return 0;
}
}

// done
zend_destroy_file_handle(&fh);
} else {
yaf_trigger_error(E_ERROR, "Argument is not a valid ini file '%s'", ini_file);
return 0;
Expand Down
23 changes: 23 additions & 0 deletions tests/110.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Bug (open file not destroy or crash in Yaf_Config_Ini, PHP 8.1 or later)
--SKIPIF--
<?php if (!extension_loaded("yaf")) print "skip"; ?>
--INI--
yaf.use_spl_autoload=0
yaf.lowcase_path=0
yaf.use_namespace=0
--FILE--
<?php
$file = dirname(__FILE__) . "/simple.ini";

// ulimit -n, default 256
// open files will be 257
for ($i = 0; $i < 257; $i++) {
$a = new Yaf_Config_Ini($file);
unset($a);
}

var_dump("Done")
?>
--EXPECTF--
string(4) "Done"
Loading