Skip to content

Commit

Permalink
Fixed bug #2051: Segfault on fatal error when setting xdebug.mode via…
Browse files Browse the repository at this point in the history
… php-fpm pool config
  • Loading branch information
derickr committed Jun 8, 2022
1 parent 3ff4465 commit 1077231
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
12 changes: 6 additions & 6 deletions src/lib/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void xdebug_disable_opcache_optimizer(void)
}


static int xdebug_lib_set_mode_item(char *mode, int len)
static int xdebug_lib_set_mode_item(const char *mode, int len)
{
if (strncmp(mode, "off", len) == 0) {
XG_LIB(mode) |= XDEBUG_MODE_OFF;
Expand Down Expand Up @@ -156,11 +156,11 @@ static int xdebug_lib_set_mode_item(char *mode, int len)
return 0;
}

static int xdebug_lib_set_mode_from_setting(char *mode)
static int xdebug_lib_set_mode_from_setting(const char *mode)
{
char *mode_ptr = mode;
char *comma = NULL;
int errors = 0;
const char *mode_ptr = mode;
char *comma = NULL;
int errors = 0;

XG_LIB(mode) = 0;

Expand All @@ -178,7 +178,7 @@ static int xdebug_lib_set_mode_from_setting(char *mode)
return !errors;
}

int xdebug_lib_set_mode(char *mode)
int xdebug_lib_set_mode(const char *mode)
{
char *config = getenv("XDEBUG_MODE");
int result = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ typedef struct _xdebug_library_globals_t {
} xdebug_library_globals_t;

typedef struct _xdebug_library_settings_t {
char *requested_mode;

char *output_dir;
char *trigger_value;

Expand Down Expand Up @@ -261,7 +263,7 @@ void xdebug_disable_opcache_optimizer(void);
#define XDEBUG_MODE_GCSTATS 1<<3
#define XDEBUG_MODE_PROFILING 1<<4
#define XDEBUG_MODE_TRACING 1<<5
int xdebug_lib_set_mode(char *mode);
int xdebug_lib_set_mode(const char *mode);

#define XDEBUG_MODE_IS_OFF() ((XG(globals.library.mode) == XDEBUG_MODE_OFF))
#define XDEBUG_MODE_IS(v) ((XG(globals.library.mode) & (v)) ? 1 : 0)
Expand Down
2 changes: 2 additions & 0 deletions tests/library/xdebug_mode_from_env-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ xdebug.mode=wrongmode
XDEBUG_MODE=develop,nonexisting
--FILE--
<?php
echo join( ',', xdebug_info( 'mode' ) );
?>
--EXPECTF--
Xdebug: [Config] Invalid mode 'develop,nonexisting' set for 'XDEBUG_MODE' environment variable, fall back to 'xdebug.mode' configuration setting (See: http%sdocs/errors#CFG-C-ENVMODE)
Xdebug: [Config] Invalid mode 'wrongmode' set for 'xdebug.mode' configuration setting (See: http%sdocs/errors#CFG-C-MODE)
Xdebug: [Config] Invalid mode 'develop,nonexisting' set for 'XDEBUG_MODE' environment variable, fall back to 'xdebug.mode' configuration setting (See: http%sdocs/errors#CFG-C-ENVMODE)
develop
20 changes: 6 additions & 14 deletions xdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,6 @@ static PHP_INI_MH(OnUpdateSession)
DUMP_TOK(session);
}

static PHP_INI_MH(OnUpdateMode)
{
if (!new_value) {
return FAILURE;
}

if (!xdebug_lib_set_mode(ZSTR_VAL(new_value))) {
return FAILURE;
}

return SUCCESS;
}

static PHP_INI_MH(OnUpdateStartWithRequest)
{
if (!new_value) {
Expand Down Expand Up @@ -284,7 +271,7 @@ ZEND_INI_DISP(display_start_upon_error)

PHP_INI_BEGIN()
/* Library settings */
PHP_INI_ENTRY( "xdebug.mode", "develop", PHP_INI_SYSTEM, OnUpdateMode)
STD_PHP_INI_ENTRY("xdebug.mode", "develop", PHP_INI_SYSTEM, OnUpdateString, settings.library.requested_mode, zend_xdebug_globals, xdebug_globals)
PHP_INI_ENTRY_EX( "xdebug.start_with_request", "default", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStartWithRequest, display_start_with_request)
PHP_INI_ENTRY_EX( "xdebug.start_upon_error", "default", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStartUponError, display_start_upon_error)
STD_PHP_INI_ENTRY("xdebug.output_dir", XDEBUG_TEMP_DIR, PHP_INI_ALL, OnUpdateString, settings.library.output_dir, zend_xdebug_globals, xdebug_globals)
Expand Down Expand Up @@ -533,6 +520,11 @@ PHP_MINIT_FUNCTION(xdebug)
ZEND_INIT_MODULE_GLOBALS(xdebug, php_xdebug_init_globals, php_xdebug_shutdown_globals);
REGISTER_INI_ENTRIES();

/* Locking in mode as it currently is */
if (!xdebug_lib_set_mode(XG(settings.library.requested_mode))) {
xdebug_lib_set_mode("develop");
}

if (XDEBUG_MODE_IS_OFF()) {
return SUCCESS;
}
Expand Down

0 comments on commit 1077231

Please sign in to comment.