Skip to content

Commit a973296

Browse files
committed
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).
1 parent eb919e8 commit a973296

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

doc/src/sgml/client-auth.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
Records cannot be continued across lines.
8181
A record is made
8282
up of a number of fields which are separated by spaces and/or tabs.
83-
Fields can contain white space if the field value is quoted.
83+
Fields can contain white space if the field value is double-quoted.
8484
Quoting one of the keywords in a database, user, or address field (e.g.,
8585
<literal>all</> or <literal>replication</>) makes the word lose its special
8686
character, and just match a database, user, or host with that name.

src/backend/parser/scansup.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ scanstr(const char *s)
5656
* appear in pairs, so there should be another character.
5757
*/
5858
i++;
59+
/* The bootstrap parser is not as smart, so check here. */
60+
Assert(s[i] == '\'');
5961
newStr[j] = s[i];
6062
}
6163
else if (s[i] == '\\')

src/bin/initdb/initdb.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ bootstrap_template1(void)
13951395
bki_lines = replace_token(bki_lines, "FLOAT8PASSBYVAL",
13961396
FLOAT8PASSBYVAL ? "true" : "false");
13971397

1398-
bki_lines = replace_token(bki_lines, "POSTGRES", username);
1398+
bki_lines = replace_token(bki_lines, "POSTGRES", escape_quotes(username));
13991399

14001400
bki_lines = replace_token(bki_lines, "ENCODING", encodingid);
14011401

@@ -2043,8 +2043,8 @@ setup_privileges(void)
20432043

20442044
PG_CMD_OPEN;
20452045

2046-
priv_lines = replace_token(privileges_setup,
2047-
"$POSTGRES_SUPERUSERNAME", username);
2046+
priv_lines = replace_token(privileges_setup, "$POSTGRES_SUPERUSERNAME",
2047+
escape_quotes(username));
20482048
for (line = priv_lines; *line != NULL; line++)
20492049
PG_CMD_PUTS(*line);
20502050

@@ -3056,7 +3056,6 @@ main(int argc, char *argv[])
30563056
canonicalize_path(pg_data);
30573057

30583058
#ifdef WIN32
3059-
30603059
/*
30613060
* Before we execute another program, make sure that we are running with a
30623061
* restricted token. If not, re-execute ourselves with one.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy