Skip to content

core: Remove disable_classes INI setting #12043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions Zend/tests/bug77494.phpt

This file was deleted.

27 changes: 27 additions & 0 deletions Zend/tests/disable_classes_warning.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Check that warning is emitted when disabling classes
--INI--
disable_classes=Exception
--FILE--
<?php
$o = new Exception();
var_dump($o);
?>
--EXPECTF--
object(Exception)#1 (7) {
["message":protected]=>
string(0) ""
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(0)
["file":protected]=>
string(%d) "%s"
["line":protected]=>
int(2)
["trace":"Exception":private]=>
array(0) {
}
["previous":"Exception":private]=>
NULL
}
17 changes: 0 additions & 17 deletions Zend/tests/errmsg_021.phpt

This file was deleted.

71 changes: 0 additions & 71 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -3579,77 +3579,6 @@ ZEND_API void zend_disable_functions(const char *function_list) /* {{{ */
}
/* }}} */

#ifdef ZEND_WIN32
#pragma optimize("", off)
#endif
static ZEND_COLD zend_object *display_disabled_class(zend_class_entry *class_type) /* {{{ */
{
zend_object *intern;

intern = zend_objects_new(class_type);

/* Initialize default properties */
if (EXPECTED(class_type->default_properties_count != 0)) {
zval *p = intern->properties_table;
zval *end = p + class_type->default_properties_count;
do {
ZVAL_UNDEF(p);
p++;
} while (p != end);
}

zend_error(E_WARNING, "%s() has been disabled for security reasons", ZSTR_VAL(class_type->name));
return intern;
}
#ifdef ZEND_WIN32
#pragma optimize("", on)
#endif
/* }}} */

static const zend_function_entry disabled_class_new[] = {
ZEND_FE_END
};

ZEND_API zend_result zend_disable_class(const char *class_name, size_t class_name_length) /* {{{ */
{
zend_class_entry *disabled_class;
zend_string *key;
zend_function *fn;
zend_property_info *prop;

key = zend_string_alloc(class_name_length, 0);
zend_str_tolower_copy(ZSTR_VAL(key), class_name, class_name_length);
disabled_class = zend_hash_find_ptr(CG(class_table), key);
zend_string_release_ex(key, 0);
if (!disabled_class) {
return FAILURE;
}

/* Will be reset by INIT_CLASS_ENTRY. */
free(disabled_class->interfaces);

INIT_CLASS_ENTRY_INIT_METHODS((*disabled_class), disabled_class_new);
disabled_class->create_object = display_disabled_class;

ZEND_HASH_MAP_FOREACH_PTR(&disabled_class->function_table, fn) {
if ((fn->common.fn_flags & (ZEND_ACC_HAS_RETURN_TYPE|ZEND_ACC_HAS_TYPE_HINTS)) &&
fn->common.scope == disabled_class) {
zend_free_internal_arg_info(&fn->internal_function);
}
} ZEND_HASH_FOREACH_END();
zend_hash_clean(&disabled_class->function_table);
ZEND_HASH_MAP_FOREACH_PTR(&disabled_class->properties_info, prop) {
if (prop->ce == disabled_class) {
zend_string_release(prop->name);
zend_type_release(prop->type, /* persistent */ 1);
free(prop);
}
} ZEND_HASH_FOREACH_END();
zend_hash_clean(&disabled_class->properties_info);
return SUCCESS;
}
/* }}} */

static zend_always_inline zend_class_entry *get_scope(zend_execute_data *frame)
{
return frame && frame->func ? frame->func->common.scope : NULL;
Expand Down
1 change: 0 additions & 1 deletion Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ static zend_always_inline zend_result zend_register_class_alias(const char *name
zend_register_class_alias_ex(ZEND_NS_NAME(ns, name), sizeof(ZEND_NS_NAME(ns, name))-1, ce, 1)

ZEND_API void zend_disable_functions(const char *function_list);
ZEND_API zend_result zend_disable_class(const char *class_name, size_t class_name_length);

ZEND_API ZEND_COLD void zend_wrong_param_count(void);
ZEND_API ZEND_COLD void zend_wrong_property_read(zval *object, zval *property);
Expand Down
54 changes: 13 additions & 41 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,41 +319,6 @@ static PHP_INI_MH(OnSetLogFilter)
}
/* }}} */

/* {{{ php_disable_classes */
static void php_disable_classes(void)
{
char *s = NULL, *e;

if (!*(INI_STR("disable_classes"))) {
return;
}

e = PG(disable_classes) = strdup(INI_STR("disable_classes"));

while (*e) {
switch (*e) {
case ' ':
case ',':
if (s) {
*e = '\0';
zend_disable_class(s, e-s);
s = NULL;
}
break;
default:
if (!s) {
s = e;
}
break;
}
e++;
}
if (s) {
zend_disable_class(s, e-s);
}
}
/* }}} */

/* {{{ php_binary_init */
static void php_binary_init(void)
{
Expand Down Expand Up @@ -660,6 +625,17 @@ static PHP_INI_MH(OnChangeMailForceExtra)
}
/* }}} */

/* Emit warning when using this INI setting as it is removed */
static PHP_INI_MH(OnChangeDisableClasses)
{
if (stage != PHP_INI_SYSTEM) {
return FAILURE;
}
php_error_docref("disable_classes", E_WARNING, "The disable_classes INI setting has been removed and has no effect");

return FAILURE;
}

/* defined in browscap.c */
PHP_INI_MH(OnChangeBrowscap);

Expand Down Expand Up @@ -757,7 +733,7 @@ PHP_INI_BEGIN()
PHP_INI_ENTRY("sendmail_path", DEFAULT_SENDMAIL_PATH, PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("mail.force_extra_parameters",NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, OnChangeMailForceExtra)
PHP_INI_ENTRY("disable_functions", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, NULL)
PHP_INI_ENTRY("disable_classes", "", PHP_INI_SYSTEM, OnChangeDisableClasses)
PHP_INI_ENTRY("max_file_uploads", "20", PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)
PHP_INI_ENTRY("max_multipart_body_parts", "-1", PHP_INI_SYSTEM|PHP_INI_PERDIR, NULL)

Expand Down Expand Up @@ -1975,9 +1951,6 @@ static void core_globals_dtor(php_core_globals *core_globals)
ZEND_ASSERT(!core_globals->last_error_message);
ZEND_ASSERT(!core_globals->last_error_file);

if (core_globals->disable_classes) {
free(core_globals->disable_classes);
}
if (core_globals->php_binary) {
free(core_globals->php_binary);
}
Expand Down Expand Up @@ -2235,9 +2208,8 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi
}
}

/* disable certain classes and functions as requested by php.ini */
/* disable certain functions as requested by php.ini */
zend_disable_functions(INI_STR("disable_functions"));
php_disable_classes();

/* make core report what it should */
if ((module = zend_hash_str_find_ptr(&module_registry, "core", sizeof("core")-1)) != NULL) {
Expand Down
1 change: 0 additions & 1 deletion main/php_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ struct _php_core_globals {

char *php_sys_temp_dir;

char *disable_classes;
zend_long max_input_nesting_level;
zend_long max_input_vars;

Expand Down
6 changes: 3 additions & 3 deletions main/php_version.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* automatically generated by configure */
/* edit configure.ac to change version number */
#define PHP_MAJOR_VERSION 8
#define PHP_MINOR_VERSION 4
#define PHP_MINOR_VERSION 3
#define PHP_RELEASE_VERSION 0
#define PHP_EXTRA_VERSION "-dev"
#define PHP_VERSION "8.4.0-dev"
#define PHP_VERSION_ID 80400
#define PHP_VERSION "8.3.0-dev"
#define PHP_VERSION_ID 80300
5 changes: 0 additions & 5 deletions php.ini-development
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,6 @@ serialize_precision = -1
; https://php.net/disable-functions
disable_functions =

; This directive allows you to disable certain classes.
; It receives a comma-delimited list of class names.
; https://php.net/disable-classes
disable_classes =

; Colors for Syntax Highlighting mode. Anything that's acceptable in
; <span style="color: ???????"> would work.
; https://php.net/syntax-highlighting
Expand Down
5 changes: 0 additions & 5 deletions php.ini-production
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,6 @@ serialize_precision = -1
; https://php.net/disable-functions
disable_functions =

; This directive allows you to disable certain classes.
; It receives a comma-delimited list of class names.
; https://php.net/disable-classes
disable_classes =

; Colors for Syntax Highlighting mode. Anything that's acceptable in
; <span style="color: ???????"> would work.
; https://php.net/syntax-highlighting
Expand Down
36 changes: 0 additions & 36 deletions sapi/fpm/fpm/fpm_php.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,6 @@ static int fpm_php_zend_ini_alter_master(char *name, int name_length, char *new_
}
/* }}} */

static void fpm_php_disable(char *value, int (*zend_disable)(const char *, size_t)) /* {{{ */
{
char *s = 0, *e = value;

while (*e) {
switch (*e) {
case ' ':
case ',':
if (s) {
*e = '\0';
zend_disable(s, e - s);
s = 0;
}
break;
default:
if (!s) {
s = e;
}
break;
}
e++;
}

if (s) {
zend_disable(s, e - s);
}
}
/* }}} */

#define FPM_PHP_INI_ALTERING_ERROR -1
#define FPM_PHP_INI_APPLIED 1
#define FPM_PHP_INI_EXTENSION_FAILED 0
Expand Down Expand Up @@ -107,13 +78,6 @@ int fpm_php_apply_defines_ex(struct key_value_s *kv, int mode) /* {{{ */
return FPM_PHP_INI_APPLIED;
}

if (!strcmp(name, "disable_classes") && *value) {
char *v = strdup(value);
PG(disable_classes) = v;
fpm_php_disable(v, zend_disable_class);
return FPM_PHP_INI_APPLIED;
}

return FPM_PHP_INI_APPLIED;
}
/* }}} */
Expand Down
5 changes: 2 additions & 3 deletions sapi/fpm/www.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,8 @@ pm.max_spare_servers = 3
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.

; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.
; extension_dir. Defining 'disable_functions' will not overwrite previously
; defined php.ini values, but will append the new value instead.

; Note: path INI options can be relative and will be expanded with the prefix
; (pool, global or @prefix@)
Expand Down
1 change: 1 addition & 0 deletions sapi/fuzzer/fuzzer-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "fuzzer.h"

#include "Zend/zend.h"
#include "main/php.h"
#include "main/php_config.h"
#include "main/php_main.h"

Expand Down
19 changes: 17 additions & 2 deletions sapi/fuzzer/fuzzer-sapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ static const char HARDCODED_INI[] =
",crypt"
/* openlog() has a known memory-management issue. */
",openlog"
/* Can cause long loops that bypass the executor step limit. */
"\ndisable_classes=InfiniteIterator"
;

static int startup(sapi_module_struct *sapi_module)
Expand Down Expand Up @@ -128,6 +126,21 @@ static sapi_module_struct fuzzer_module = {
STANDARD_SAPI_MODULE_PROPERTIES
};

static ZEND_COLD zend_object *disable_class_create_handler(zend_class_entry *class_type) /* {{{ */
{
zend_throw_error(NULL, "Cannot construct class %s, as it is disabled", ZSTR_VAL(class_type->name));
return NULL;
}

static void fuzzer_disable_classes(void)
{
/* Overwrite built-in constructor for InfiniteIterator as it
* can cause long loops that bypass the executor step limit. */
/* Lowercase as this is how the CE as stored */
zend_class_entry *InfiniteIterator_class = zend_hash_str_find(CG(class_table), "infiniteiterator", strlen("infiniteiterator"));
InfiniteIterator_class->create_object = disable_class_create_handler;
}

int fuzzer_init_php(const char *extra_ini)
{
#ifdef __SANITIZE_ADDRESS__
Expand Down Expand Up @@ -183,6 +196,8 @@ int fuzzer_request_startup(void)
SIGG(check) = 0;
#endif

fuzzer_disable_classes();

return SUCCESS;
}

Expand Down
Loading
Loading