1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-7883 don't close not open file handle

don't create a stream if file is not open
This commit is contained in:
Remi Collet
2022-01-17 10:23:15 +01:00
committed by Remi Collet
parent 69f6b09b2a
commit cdfc4d3596
3 changed files with 9 additions and 4 deletions

1
NEWS
View File

@@ -6,6 +6,7 @@ PHP NEWS
. Fixed bug #81430 (Attribute instantiation leaves dangling pointer).
(beberlei)
. Fixed bug GH-7896 (Environment vars may be mangled on Windows). (cmb)
. Fixed bug GH-7883 (Segfault when INI file is not readable). (Remi)
- FFI:
. Fixed bug GH-7867 (FFI::cast() from pointer to array is broken). (cmb,

View File

@@ -214,7 +214,10 @@ static void zend_file_handle_dtor(zend_file_handle *fh) /* {{{ */
{
switch (fh->type) {
case ZEND_HANDLE_FP:
fclose(fh->handle.fp);
if (fh->handle.fp) {
fclose(fh->handle.fp);
fh->handle.fp = NULL;
}
break;
case ZEND_HANDLE_STREAM:
if (fh->handle.stream.closer && fh->handle.stream.handle) {

View File

@@ -686,8 +686,9 @@ int php_init_config(void)
if (VCWD_STAT(ini_file, &sb) == 0) {
if (S_ISREG(sb.st_mode)) {
zend_file_handle fh;
zend_stream_init_fp(&fh, VCWD_FOPEN(ini_file, "r"), ini_file);
if (fh.handle.fp) {
FILE *file = VCWD_FOPEN(ini_file, "r");
if (file) {
zend_stream_init_fp(&fh, file, ini_file);
if (zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash) == SUCCESS) {
/* Here, add it to the list of ini files read */
l = (int)strlen(ini_file);
@@ -695,8 +696,8 @@ int php_init_config(void)
p = estrndup(ini_file, l);
zend_llist_add_element(&scanned_ini_list, &p);
}
zend_destroy_file_handle(&fh);
}
zend_destroy_file_handle(&fh);
}
}
free(namelist[i]);