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

Replace usage of "addslashes" with prepared statements #16708

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 4 additions & 4 deletions lib/private/Setup/PostgreSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function setupDatabase($username) {
private function createDatabase(Connection $connection) {
if (!$this->databaseExists($connection)) {
//The database does not exists... let's create it
$query = $connection->prepare("CREATE DATABASE " . addslashes($this->dbName) . " OWNER " . addslashes($this->dbUser));
$query = $connection->prepare('CREATE DATABASE ' . pg_escape_identifier($this->dbName) . ' OWNER ' . pg_escape_identifier($this->dbUser));
try {
$query->execute();
} catch (DatabaseException $e) {
Expand All @@ -118,7 +118,7 @@ private function createDatabase(Connection $connection) {
]);
}
} else {
$query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC");
$query = $connection->prepare('REVOKE ALL PRIVILEGES ON DATABASE ' . pg_escape_identifier($this->dbName) . ' FROM PUBLIC');
try {
$query->execute();
} catch (DatabaseException $e) {
Expand Down Expand Up @@ -159,10 +159,10 @@ private function createDBUser(Connection $connection) {
}

// create the user
$query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'");
$query = $connection->prepare('CREATE USER ' . pg_escape_identifier($this->dbUser) . ' CREATEDB PASSWORD ' . pg_escape_literal($this->dbPassword));
$query->execute();
if ($this->databaseExists($connection)) {
$query = $connection->prepare('GRANT CONNECT ON DATABASE ' . addslashes($this->dbName) . ' TO '.addslashes($this->dbUser));
$query = $connection->prepare('GRANT CONNECT ON DATABASE ' . pg_escape_identifier($this->dbName) . ' TO ' . pg_escape_identifier($this->dbUser));
$query->execute();
}
} catch (DatabaseException $e) {
Expand Down