From 8eb48e281287646bb186f831e4f076f4557a14a9 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Thu, 6 Sep 2018 14:15:08 +0200 Subject: [PATCH 1/2] [ticket/15742] Remove get_magic_quotes_gpc() call PHPBB3-15742 --- phpBB/phpbb/request/request.php | 2 - phpBB/phpbb/request/type_cast_helper.php | 37 ------------------- .../request/type_cast_helper_interface.php | 7 ---- 3 files changed, 46 deletions(-) diff --git a/phpBB/phpbb/request/request.php b/phpBB/phpbb/request/request.php index 00be8fd381..a0267d1370 100644 --- a/phpBB/phpbb/request/request.php +++ b/phpBB/phpbb/request/request.php @@ -150,8 +150,6 @@ class request implements \phpbb\request\request_interface return; } - $this->type_cast_helper->add_magic_quotes($value); - // setting to null means unsetting if ($value === null) { diff --git a/phpBB/phpbb/request/type_cast_helper.php b/phpBB/phpbb/request/type_cast_helper.php index 96e66950ca..1a53206c74 100644 --- a/phpBB/phpbb/request/type_cast_helper.php +++ b/phpBB/phpbb/request/type_cast_helper.php @@ -18,28 +18,6 @@ namespace phpbb\request; */ class type_cast_helper implements \phpbb\request\type_cast_helper_interface { - - /** - * @var string Whether slashes need to be stripped from input - */ - protected $strip; - - /** - * Initialises the type cast helper class. - * All it does is find out whether magic quotes are turned on. - */ - public function __construct() - { - if (version_compare(PHP_VERSION, '5.4.0-dev', '>=')) - { - $this->strip = false; - } - else - { - $this->strip = (@get_magic_quotes_gpc()) ? true : false; - } - } - /** * Recursively applies addslashes to a variable. * @@ -68,19 +46,6 @@ class type_cast_helper implements \phpbb\request\type_cast_helper_interface } } - /** - * Recursively applies addslashes to a variable if magic quotes are turned on. - * - * @param mixed &$var Variable passed by reference to which slashes will be added. - */ - public function add_magic_quotes(&$var) - { - if ($this->strip) - { - $this->addslashes_recursively($var); - } - } - /** * Set variable $result to a particular type. * @@ -129,8 +94,6 @@ class type_cast_helper implements \phpbb\request\type_cast_helper_interface $result = preg_replace('/[\x80-\xFF]/', '?', $result); } } - - $result = ($this->strip) ? stripslashes($result) : $result; } } diff --git a/phpBB/phpbb/request/type_cast_helper_interface.php b/phpBB/phpbb/request/type_cast_helper_interface.php index 2cb28d021f..e22712dc0c 100644 --- a/phpBB/phpbb/request/type_cast_helper_interface.php +++ b/phpBB/phpbb/request/type_cast_helper_interface.php @@ -25,13 +25,6 @@ interface type_cast_helper_interface */ public function addslashes_recursively(&$var); - /** - * Recursively applies addslashes to a variable if magic quotes are turned on. - * - * @param mixed &$var Variable passed by reference to which slashes will be added. - */ - public function add_magic_quotes(&$var); - /** * Set variable $result to a particular type. * From 89d1401a77f7a2f9ee067b90efa975e21363e914 Mon Sep 17 00:00:00 2001 From: Jakub Senko Date: Thu, 13 Sep 2018 18:47:14 +0200 Subject: [PATCH 2/2] [ticket/15742] Remove addslashes_recursively() PHPBB3-15742 --- phpBB/phpbb/request/type_cast_helper.php | 28 ------------------- .../request/type_cast_helper_interface.php | 7 ----- tests/request/type_cast_helper_test.php | 10 ------- 3 files changed, 45 deletions(-) diff --git a/phpBB/phpbb/request/type_cast_helper.php b/phpBB/phpbb/request/type_cast_helper.php index 1a53206c74..912494998d 100644 --- a/phpBB/phpbb/request/type_cast_helper.php +++ b/phpBB/phpbb/request/type_cast_helper.php @@ -18,34 +18,6 @@ namespace phpbb\request; */ class type_cast_helper implements \phpbb\request\type_cast_helper_interface { - /** - * Recursively applies addslashes to a variable. - * - * @param mixed &$var Variable passed by reference to which slashes will be added. - */ - public function addslashes_recursively(&$var) - { - if (is_string($var)) - { - $var = addslashes($var); - } - else if (is_array($var)) - { - $var_copy = $var; - $var = array(); - foreach ($var_copy as $key => $value) - { - if (is_string($key)) - { - $key = addslashes($key); - } - $var[$key] = $value; - - $this->addslashes_recursively($var[$key]); - } - } - } - /** * Set variable $result to a particular type. * diff --git a/phpBB/phpbb/request/type_cast_helper_interface.php b/phpBB/phpbb/request/type_cast_helper_interface.php index e22712dc0c..9671573bf1 100644 --- a/phpBB/phpbb/request/type_cast_helper_interface.php +++ b/phpBB/phpbb/request/type_cast_helper_interface.php @@ -18,13 +18,6 @@ namespace phpbb\request; */ interface type_cast_helper_interface { - /** - * Recursively applies addslashes to a variable. - * - * @param mixed &$var Variable passed by reference to which slashes will be added. - */ - public function addslashes_recursively(&$var); - /** * Set variable $result to a particular type. * diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php index 143c05aa9c..6407dca894 100644 --- a/tests/request/type_cast_helper_test.php +++ b/tests/request/type_cast_helper_test.php @@ -20,16 +20,6 @@ class phpbb_type_cast_helper_test extends phpbb_test_case $this->type_cast_helper = new \phpbb\request\type_cast_helper(); } - public function test_addslashes_recursively() - { - $data = array('some"string' => array('that"' => 'really"', 'needs"' => '"escaping')); - $expected = array('some\\"string' => array('that\\"' => 'really\\"', 'needs\\"' => '\\"escaping')); - - $this->type_cast_helper->addslashes_recursively($data); - - $this->assertEquals($expected, $data); - } - public function test_simple_recursive_set_var() { $data = 'eviL<3';