Skip to content

Commit ac1c2dc

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix GH-7883 don't close not open file handle don't create a stream if file is not open
2 parents 58cbee1 + cdfc4d3 commit ac1c2dc

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Zend/zend_stream.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,10 @@ static void zend_file_handle_dtor(zend_file_handle *fh) /* {{{ */
214214
{
215215
switch (fh->type) {
216216
case ZEND_HANDLE_FP:
217-
fclose(fh->handle.fp);
217+
if (fh->handle.fp) {
218+
fclose(fh->handle.fp);
219+
fh->handle.fp = NULL;
220+
}
218221
break;
219222
case ZEND_HANDLE_STREAM:
220223
if (fh->handle.stream.closer && fh->handle.stream.handle) {

main/php_ini.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,17 +686,18 @@ int php_init_config(void)
686686
if (VCWD_STAT(ini_file, &sb) == 0) {
687687
if (S_ISREG(sb.st_mode)) {
688688
zend_file_handle fh;
689-
zend_stream_init_fp(&fh, VCWD_FOPEN(ini_file, "r"), ini_file);
690-
if (fh.handle.fp) {
689+
FILE *file = VCWD_FOPEN(ini_file, "r");
690+
if (file) {
691+
zend_stream_init_fp(&fh, file, ini_file);
691692
if (zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash) == SUCCESS) {
692693
/* Here, add it to the list of ini files read */
693694
l = (int)strlen(ini_file);
694695
total_l += l + 2;
695696
p = estrndup(ini_file, l);
696697
zend_llist_add_element(&scanned_ini_list, &p);
697698
}
699+
zend_destroy_file_handle(&fh);
698700
}
699-
zend_destroy_file_handle(&fh);
700701
}
701702
}
702703
free(namelist[i]);

0 commit comments

Comments
 (0)