Skip to content

Commit

Permalink
Merge pull request #587 from xinhaiz/ini_init_openfile_destroy
Browse files Browse the repository at this point in the history
open file not destroy or crash in Yaf_Config_Ini, PHP 8.1 or later
  • Loading branch information
laruence authored Jun 26, 2024
2 parents ccee505 + dd773c8 commit 34e9f43
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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"

0 comments on commit 34e9f43

Please sign in to comment.