]> source.dussan.org Git - nextcloud-server.git/commitdiff
Quote database and role in queries 2556/head
authorLari Tikkanen <lartza@outlook.com>
Wed, 7 Dec 2016 20:12:25 +0000 (22:12 +0200)
committerLari Tikkanen <lartza@outlook.com>
Wed, 7 Dec 2016 20:12:25 +0000 (22:12 +0200)
Fixes #1793
Signed-off-by: Lari Tikkanen <lartza@outlook.com>
lib/private/Setup/PostgreSQL.php

index 14325a18efee777e552c2ebeb31312fa2ce72269..4f4f8a03231f87bd86d996071580422cf4234c5a 100644 (file)
@@ -111,7 +111,7 @@ class PostgreSQL extends AbstractDatabase {
        private function createDatabase(IDBConnection $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 \"" . addslashes($this->dbName) . "\" OWNER '" . addslashes($this->dbUser) . "'");
                        try {
                                $query->execute();
                        } catch (DatabaseException $e) {
@@ -119,7 +119,7 @@ class PostgreSQL extends AbstractDatabase {
                                $this->logger->logException($e);
                        }
                } else {
-                       $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC");
+                       $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE \"" . addslashes($this->dbName) . "\" FROM PUBLIC");
                        try {
                                $query->execute();
                        } catch (DatabaseException $e) {
@@ -153,10 +153,10 @@ class PostgreSQL extends AbstractDatabase {
                try {
                        if ($this->userExists($connection)) {
                                // change the password
-                               $query = $connection->prepare("ALTER ROLE " . addslashes($this->dbUser) . " WITH CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'");
+                               $query = $connection->prepare("ALTER ROLE \"" . addslashes($this->dbUser) . "\" WITH CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'");
                        } else {
                                // create the user
-                               $query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'");
+                               $query = $connection->prepare("CREATE USER \"" . addslashes($this->dbUser) . "\" CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'");
                        }
                        $query->execute();
                } catch (DatabaseException $e) {