Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

+1-1
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

+2
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

+3-4
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)