[ticket/9066] Disallow some database prefix to prevent same errors and problems

With this patch database prefixes must not be empty and only contain
alphanumeric characters, numbers and underscores.

PHPBB3-9066
This commit is contained in:
Joas Schilling 2011-10-17 23:22:36 +02:00
parent 86f8851c40
commit 6370ef2705
2 changed files with 8 additions and 1 deletions

View file

@ -546,6 +546,11 @@ class install_install extends module
$error[] = $lang['INST_ERR_NO_DB']; $error[] = $lang['INST_ERR_NO_DB'];
$connect_test = false; $connect_test = false;
} }
else if (!preg_match('#^[a-zA-Z][a-zA-Z0-9_]*$#', $data['table_prefix'], $result))
{
$error[] = $lang['INST_ERR_DB_INVALID_PREFIX'];
$connect_test = false;
}
else else
{ {
$connect_test = connect_check_db(true, $error, $available_dbms[$data['dbms']], $data['table_prefix'], $data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport']); $connect_test = connect_check_db(true, $error, $available_dbms[$data['dbms']], $data['table_prefix'], $data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport']);
@ -2032,7 +2037,7 @@ class install_install extends module
'dbname' => array('lang' => 'DB_NAME', 'type' => 'text:25:100', 'explain' => false), 'dbname' => array('lang' => 'DB_NAME', 'type' => 'text:25:100', 'explain' => false),
'dbuser' => array('lang' => 'DB_USERNAME', 'type' => 'text:25:100', 'explain' => false), 'dbuser' => array('lang' => 'DB_USERNAME', 'type' => 'text:25:100', 'explain' => false),
'dbpasswd' => array('lang' => 'DB_PASSWORD', 'type' => 'password:25:100', 'explain' => false), 'dbpasswd' => array('lang' => 'DB_PASSWORD', 'type' => 'password:25:100', 'explain' => false),
'table_prefix' => array('lang' => 'TABLE_PREFIX', 'type' => 'text:25:100', 'explain' => false), 'table_prefix' => array('lang' => 'TABLE_PREFIX', 'type' => 'text:25:100', 'explain' => true),
); );
var $admin_config_options = array( var $admin_config_options = array(
'legend1' => 'ADMIN_CONFIG', 'legend1' => 'ADMIN_CONFIG',

View file

@ -232,6 +232,7 @@ $lang = array_merge($lang, array(
'INST_ERR' => 'Installation error', 'INST_ERR' => 'Installation error',
'INST_ERR_DB_CONNECT' => 'Could not connect to the database, see error message below.', 'INST_ERR_DB_CONNECT' => 'Could not connect to the database, see error message below.',
'INST_ERR_DB_FORUM_PATH' => 'The database file specified is within your board directory tree. You should put this file in a non web-accessible location.', 'INST_ERR_DB_FORUM_PATH' => 'The database file specified is within your board directory tree. You should put this file in a non web-accessible location.',
'INST_ERR_DB_INVALID_PREFIX'=> 'The prefix you entered is invalid. It must start with an alphanumeric character and must only contain alphanumeric characters, numbers and underscores.',
'INST_ERR_DB_NO_ERROR' => 'No error message given.', 'INST_ERR_DB_NO_ERROR' => 'No error message given.',
'INST_ERR_DB_NO_MYSQLI' => 'The version of MySQL installed on this machine is incompatible with the “MySQL with MySQLi Extension” option you have selected. Please try the “MySQL” option instead.', 'INST_ERR_DB_NO_MYSQLI' => 'The version of MySQL installed on this machine is incompatible with the “MySQL with MySQLi Extension” option you have selected. Please try the “MySQL” option instead.',
'INST_ERR_DB_NO_SQLITE' => 'The version of the SQLite extension you have installed is too old, it must be upgraded to at least 2.8.2.', 'INST_ERR_DB_NO_SQLITE' => 'The version of the SQLite extension you have installed is too old, it must be upgraded to at least 2.8.2.',
@ -352,6 +353,7 @@ $lang = array_merge($lang, array(
'TABLES_MISSING' => 'Could not find these tables<br />» <strong>%s</strong>.', 'TABLES_MISSING' => 'Could not find these tables<br />» <strong>%s</strong>.',
'TABLE_PREFIX' => 'Prefix for tables in database', 'TABLE_PREFIX' => 'Prefix for tables in database',
'TABLE_PREFIX_EXPLAIN' => 'The prefix must start with an alphanumeric character and must only contain alphanumeric characters, numbers and underscores.',
'TABLE_PREFIX_SAME' => 'The table prefix needs to be the one used by the software you are converting from.<br />» Specified table prefix was %s.', 'TABLE_PREFIX_SAME' => 'The table prefix needs to be the one used by the software you are converting from.<br />» Specified table prefix was %s.',
'TESTS_PASSED' => 'Tests passed', 'TESTS_PASSED' => 'Tests passed',
'TESTS_FAILED' => 'Tests failed', 'TESTS_FAILED' => 'Tests failed',