diff --git a/NEWS b/NEWS index 39c1d484f3f..a35589a51b0 100644 --- a/NEWS +++ b/NEWS @@ -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, diff --git a/Zend/zend_stream.c b/Zend/zend_stream.c index aadc62558e6..ae2c734b09b 100644 --- a/Zend/zend_stream.c +++ b/Zend/zend_stream.c @@ -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) { diff --git a/main/php_ini.c b/main/php_ini.c index fd6f3664882..136942896da 100644 --- a/main/php_ini.c +++ b/main/php_ini.c @@ -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]);