Skip to content

Commit cdfc4d3

Browse files
committed
Fix GH-7883 don't close not open file handle
don't create a stream if file is not open
1 parent 69f6b09 commit cdfc4d3

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PHP NEWS
66
. Fixed bug #81430 (Attribute instantiation leaves dangling pointer).
77
(beberlei)
88
. Fixed bug GH-7896 (Environment vars may be mangled on Windows). (cmb)
9+
. Fixed bug GH-7883 (Segfault when INI file is not readable). (Remi)
910

1011
- FFI:
1112
. Fixed bug GH-7867 (FFI::cast() from pointer to array is broken). (cmb,

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)