Skip to content

Commit c407243

Browse files
committed
Fix GH-10052: Browscap crashes PHP 8.1.12 on request shutdown (apache2)
get_browser() implements a lazy parse system for the browscap INI configuration. There are two possible moments when a browscap configuration can be loaded: during module startup or during request. In case of module startup, the strings are persistent strings, while for the request they are not. The INI parser must therefore know whether to create persistent or non-persistent strings. It does this by looking at CG(ini_parser_unbuffered_errors). If that value is 1 it's persistent, otherwise non-persistent. Note that this also controls how the errors are reported: if it's 1 then the errors are sent to stderr, otherwise we get E_WARNINGs. Currently, a hardcoded value of 1 is always used for that CG value in browscap_read_file(). This means we'll always create persistent strings *and* we'll not report parse errors correctly as E_WARNINGs. We fix both the crash and the lack of warnings by passing the value of persistent instead of a hardcoded 1. This is also in line with how other INI parsing code is called in ext/standard: they also make sure that during request a value of 0 is passed. Closes GH-10883.
1 parent 122f128 commit c407243

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ PHP NEWS
5151

5252
- Standard:
5353
. Fixed bug GH-10885 (stream_socket_server context leaks). (ilutov)
54+
. Fixed bug GH-10052 (Browscap crashes PHP 8.1.12 on request shutdown
55+
(apache2)). (nielsdos)
5456

5557
16 Mar 2023, PHP 8.1.17
5658

ext/standard/browscap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ static int browscap_read_file(char *filename, browser_data *browdata, int persis
432432
ctx.current_section_name = NULL;
433433
zend_hash_init(&ctx.str_interned, 8, NULL, str_interned_dtor, persistent);
434434

435-
zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_RAW,
435+
zend_parse_ini_file(&fh, persistent, ZEND_INI_SCANNER_RAW,
436436
(zend_ini_parser_cb_t) php_browscap_parser_cb, &ctx);
437437

438438
/* Destroy parser context */

0 commit comments

Comments
 (0)