Skip to content
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

Better sanitize database queries in installer #815

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Changes from 1 commit
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
34 changes: 17 additions & 17 deletions htdocs/install/page_dbsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
case 'pdo.mysql':
try {
$link = new PDO('mysql:host=' . $vars['DB_HOST'],
$vars['DB_USER'],
$vars['DB_PASS'],
array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_PERSISTENT => !empty($vars['DB_PCONNECT'])
));
$vars['DB_USER'],
$vars['DB_PASS'],
array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_PERSISTENT => !empty($vars['DB_PCONNECT'])
));
} catch (PDOException $ex) {
$error = ERR_NO_DBCONNECTION;
}
Expand Down Expand Up @@ -236,19 +236,19 @@ function select_db($db_name, $link) {
if (empty ($error)) {
if (!select_db($vars ['DB_NAME'], $link)) {
// Database not here: try to create it
$result = exec_query("CREATE DATABASE `" . $vars ['DB_NAME'] . '`', $link);
$result = exec_query("CREATE DATABASE `" . quote_sql($vars ['DB_NAME']) . '`', $link);
fiammybe marked this conversation as resolved.
Show resolved Hide resolved
if (!$result) {
$error = ERR_NO_DATABASE;
} else {
$error = sprintf(DATABASE_CREATED, $vars ['DB_NAME']);
$error = sprintf(DATABASE_CREATED, quote_sql($vars ['DB_NAME']));
$db_exist = true;
}
} else {
$db_exist = true;
}
if ($db_exist && $vars['DB_CHARSET']) {
/* Attempt to set the character set and collation to the selected */
$sql = "ALTER DATABASE `" . $vars ['DB_NAME'] . "` DEFAULT CHARACTER SET " . quote_sql($vars ['DB_CHARSET']) . ($vars ['DB_COLLATION']?" COLLATE " . quote_sql($vars ['DB_COLLATION']):"");
$sql = "ALTER DATABASE `" . quote_sql($vars ['DB_NAME']) . "` DEFAULT CHARACTER SET " . quote_sql($vars ['DB_CHARSET']) . (quote_sql($vars ['DB_COLLATION'])?" COLLATE " . quote_sql($vars ['DB_COLLATION']):"");
fiammybe marked this conversation as resolved.
Show resolved Hide resolved
if (!exec_query($sql, $link)) {
/* if the alter statement fails, set the constants to match existing */
$sql = "USE " . quote_sql($vars["DB_NAME"]);
Expand All @@ -261,8 +261,8 @@ function select_db($db_name, $link) {
$character_sets[$row["Variable_name"]] = $row["Value"];
}
$vars["DB_CHARSET"] = $character_sets["character_set_database"]
?$character_sets["character_set_database"]
: $character_sets["character_set_server"];
?$character_sets["character_set_database"]
: $character_sets["character_set_server"];

/* get the collation for the current database */
$sql = "SHOW VARIABLES LIKE 'collation%'";
Expand All @@ -271,8 +271,8 @@ function select_db($db_name, $link) {
$collations[$row["Variable_name"]] = $row["Value"];
}
$vars["DB_COLLATION"] = $collations["collation_database"]
?$collations["collation_database"]
: $collations["collation_server"];
?$collations["collation_database"]
: $collations["collation_server"];
}
}
}
Expand Down Expand Up @@ -353,10 +353,10 @@ function setFormFieldCollation(id, val) {
document.getElementById(id).style.display='display';
}
new Ajax.Updater(
id, '<?php
echo $_SERVER ['PHP_SELF'];
?>',
{ method:'get',parameters:'action=updateCollation&charset='+val }
id, '<?php
echo $_SERVER ['PHP_SELF'];
?>',
{ method:'get',parameters:'action=updateCollation&charset='+val }
);
}
</script>
Expand Down