diff options
Diffstat (limited to 'phpBB/phpbb')
6 files changed, 109 insertions, 36 deletions
| diff --git a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php index c168d26425..a40d457466 100644 --- a/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php +++ b/phpBB/phpbb/install/helper/iohandler/ajax_iohandler.php @@ -123,6 +123,14 @@ class ajax_iohandler extends iohandler_base  	/**  	 * {@inheritdoc}  	 */ +	public function get_raw_input($name, $default) +	{ +		return $this->request->raw_variable($name, $default); +	} + +	/** +	 * {@inheritdoc} +	 */  	public function get_server_variable($name, $default = '')  	{  		return $this->request->server($name, $default); diff --git a/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php b/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php index 196cdcdaab..4117a3dfd3 100644 --- a/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php +++ b/phpBB/phpbb/install/helper/iohandler/cli_iohandler.php @@ -74,6 +74,20 @@ class cli_iohandler extends iohandler_base  		return $result;  	} +	/** +	 * {@inheritdoc} +	 */ +	public function get_raw_input($name, $default) +	{ +		return $this->get_input($name, $default, true); +	} + +	/** +	 * Set input variable +	 * +	 * @param string $name Name of input variable +	 * @param mixed $value Value of input variable +	 */  	public function set_input($name, $value)  	{  		$this->input_values[$name] = $value; diff --git a/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php b/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php index f22f33d9cb..440748901c 100644 --- a/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php +++ b/phpBB/phpbb/install/helper/iohandler/iohandler_interface.php @@ -39,9 +39,20 @@ interface iohandler_interface  	public function get_input($name, $default, $multibyte = false);  	/** +	 * Returns raw input variable +	 * +	 * @param string	$name		Name of the input variable to obtain +	 * @param mixed		$default	A default value that is returned if the variable was not set. +	 * 								This function will always return a value of the same type as the default. +	 * +	 * @return mixed	Value of the raw input variable +	 */ +	public function get_raw_input($name, $default); + +	/**  	 * Returns server variable  	 * -	 * This function should work the same as request_interterface::server(). +	 * This function should work the same as request_interface::server().  	 *  	 * @param string	$name		Name of the server variable  	 * @param mixed		$default	Default value to return when the requested variable does not exist @@ -51,7 +62,7 @@ interface iohandler_interface  	public function get_server_variable($name, $default = '');  	/** -	 * Wrapper function for request_interterface::header() +	 * Wrapper function for request_interface::header()  	 *  	 * @param string	$name		Name of the request header variable  	 * @param mixed		$default	Default value to return when the requested variable does not exist diff --git a/phpBB/phpbb/install/module/obtain_data/task/obtain_database_data.php b/phpBB/phpbb/install/module/obtain_data/task/obtain_database_data.php index ce720dbf76..dc7b060746 100644 --- a/phpBB/phpbb/install/module/obtain_data/task/obtain_database_data.php +++ b/phpBB/phpbb/install/module/obtain_data/task/obtain_database_data.php @@ -79,7 +79,7 @@ class obtain_database_data extends \phpbb\install\task_base implements \phpbb\in  		$dbhost			= $this->io_handler->get_input('dbhost', '', true);  		$dbport			= $this->io_handler->get_input('dbport', '');  		$dbuser			= $this->io_handler->get_input('dbuser', ''); -		$dbpasswd		= $this->io_handler->get_input('dbpasswd', '', true); +		$dbpasswd		= $this->io_handler->get_raw_input('dbpasswd', '');  		$dbname			= $this->io_handler->get_input('dbname', '');  		$table_prefix	= $this->io_handler->get_input('table_prefix', ''); diff --git a/phpBB/phpbb/request/request.php b/phpBB/phpbb/request/request.php index 4cac6fbaea..92d4213180 100644 --- a/phpBB/phpbb/request/request.php +++ b/phpBB/phpbb/request/request.php @@ -225,6 +225,51 @@ class request implements \phpbb\request\request_interface  	}  	/** +	 * {@inheritdoc} +	 */ +	public function raw_variable($var_name, $default, $super_global = \phpbb\request\request_interface::REQUEST) +	{ +		$path = false; + +		// deep direct access to multi dimensional arrays +		if (is_array($var_name)) +		{ +			$path = $var_name; +			// make sure at least the variable name is specified +			if (empty($path)) +			{ +				return (is_array($default)) ? array() : $default; +			} +			// the variable name is the first element on the path +			$var_name = array_shift($path); +		} + +		if (!isset($this->input[$super_global][$var_name])) +		{ +			return (is_array($default)) ? array() : $default; +		} +		$var = $this->input[$super_global][$var_name]; + +		if ($path) +		{ +			// walk through the array structure and find the element we are looking for +			foreach ($path as $key) +			{ +				if (is_array($var) && isset($var[$key])) +				{ +					$var = $var[$key]; +				} +				else +				{ +					return (is_array($default)) ? array() : $default; +				} +			} +		} + +		return $var; +	} + +	/**  	* Shortcut method to retrieve SERVER variables.  	*  	* Also fall back to getenv(), some CGI setups may need it (probably not, but @@ -369,41 +414,14 @@ class request implements \phpbb\request\request_interface  	*/  	protected function _variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST, $trim = true)  	{ -		$path = false; - -		// deep direct access to multi dimensional arrays -		if (is_array($var_name)) -		{ -			$path = $var_name; -			// make sure at least the variable name is specified -			if (empty($path)) -			{ -				return (is_array($default)) ? array() : $default; -			} -			// the variable name is the first element on the path -			$var_name = array_shift($path); -		} +		$var = $this->raw_variable($var_name, $default, $super_global); -		if (!isset($this->input[$super_global][$var_name])) +		// Return prematurely if raw variable is empty array or the same as +		// the default. Using strict comparison to ensure that one can't +		// prevent proper type checking on any input variable +		if ($var === array() || $var === $default)  		{ -			return (is_array($default)) ? array() : $default; -		} -		$var = $this->input[$super_global][$var_name]; - -		if ($path) -		{ -			// walk through the array structure and find the element we are looking for -			foreach ($path as $key) -			{ -				if (is_array($var) && isset($var[$key])) -				{ -					$var = $var[$key]; -				} -				else -				{ -					return (is_array($default)) ? array() : $default; -				} -			} +			return $var;  		}  		$this->type_cast_helper->recursive_set_var($var, $default, $multibyte, $trim); diff --git a/phpBB/phpbb/request/request_interface.php b/phpBB/phpbb/request/request_interface.php index 47b3b3a4ed..3bfa8bb424 100644 --- a/phpBB/phpbb/request/request_interface.php +++ b/phpBB/phpbb/request/request_interface.php @@ -65,6 +65,28 @@ interface request_interface  	public function variable($var_name, $default, $multibyte = false, $super_global = \phpbb\request\request_interface::REQUEST);  	/** +	 * Get a variable without trimming strings and without escaping. +	 * This method MUST NOT be used with queries. +	 * Same functionality as variable(), except does not run trim() on strings +	 * and does not escape input. +	 * This method should only be used when the raw input is needed without +	 * any escaping, i.e. for database password during the installation. +	 * +	 * @param	string|array	$var_name	The form variable's name from which data shall be retrieved. +	 * 										If the value is an array this may be an array of indizes which will give +	 * 										direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a") +	 * 										then specifying array("var", 1) as the name will return "a". +	 * @param	mixed			$default	A default value that is returned if the variable was not set. +	 * 										This function will always return a value of the same type as the default. +	 * @param	\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE	$super_global +	 * 										Specifies which super global should be used +	 * +	 * @return	mixed	The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the +	 *					the same as that of $default. If the variable is not set $default is returned. +	 */ +	public function raw_variable($var_name, $default, $super_global = \phpbb\request\request_interface::REQUEST); + +	/**  	* Shortcut method to retrieve SERVER variables.  	*  	* @param	string|array	$var_name		See \phpbb\request\request_interface::variable | 
