aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2012-08-15 11:23:04 -0400
committerBruce Momjian <bruce@momjian.us>2012-08-15 11:23:15 -0400
commita973296598f2d1eec48138a2ce4f3e63410d9ed0 (patch)
tree0b76eb29da9181bdfcc4189649bc0faaed4eb6bb /src
parenteb919e8fde4333d4a627d349a1460b07fc52dd3b (diff)
downloadpostgresql-a973296598f2d1eec48138a2ce4f3e63410d9ed0.tar.gz
postgresql-a973296598f2d1eec48138a2ce4f3e63410d9ed0.zip
Properly escape usernames in initdb, so names with single-quotes are
supported. Also add assert to catch future breakage. Also, improve documentation that "double"-quotes must be used in pg_hba.conf (not single quotes).
Diffstat (limited to 'src')
-rw-r--r--src/backend/parser/scansup.c2
-rw-r--r--src/bin/initdb/initdb.c7
2 files changed, 5 insertions, 4 deletions
diff --git a/src/backend/parser/scansup.c b/src/backend/parser/scansup.c
index 6101457a109..b8e2f71d656 100644
--- a/src/backend/parser/scansup.c
+++ b/src/backend/parser/scansup.c
@@ -56,6 +56,8 @@ scanstr(const char *s)
* appear in pairs, so there should be another character.
*/
i++;
+ /* The bootstrap parser is not as smart, so check here. */
+ Assert(s[i] == '\'');
newStr[j] = s[i];
}
else if (s[i] == '\\')
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 132ad0fa4cd..a53760af85c 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -1395,7 +1395,7 @@ bootstrap_template1(void)
bki_lines = replace_token(bki_lines, "FLOAT8PASSBYVAL",
FLOAT8PASSBYVAL ? "true" : "false");
- bki_lines = replace_token(bki_lines, "POSTGRES", username);
+ bki_lines = replace_token(bki_lines, "POSTGRES", escape_quotes(username));
bki_lines = replace_token(bki_lines, "ENCODING", encodingid);
@@ -2043,8 +2043,8 @@ setup_privileges(void)
PG_CMD_OPEN;
- priv_lines = replace_token(privileges_setup,
- "$POSTGRES_SUPERUSERNAME", username);
+ priv_lines = replace_token(privileges_setup, "$POSTGRES_SUPERUSERNAME",
+ escape_quotes(username));
for (line = priv_lines; *line != NULL; line++)
PG_CMD_PUTS(*line);
@@ -3056,7 +3056,6 @@ main(int argc, char *argv[])
canonicalize_path(pg_data);
#ifdef WIN32
-
/*
* Before we execute another program, make sure that we are running with a
* restricted token. If not, re-execute ourselves with one.