Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1fSl-0001h2-EO for pgsql-bugs@postgresql.org; Wed, 15 Aug 2012 15:24:51 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1fSk-0005qD-1W for pgsql-bugs@postgresql.org; Wed, 15 Aug 2012 15:24:50 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1T1fSj-0007G5-2P; Wed, 15 Aug 2012 11:24:49 -0400 Date: Wed, 15 Aug 2012 11:24:49 -0400 From: Bruce Momjian To: Emmanuel Guyot Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6162: initdb : Windows username isn't escaped Message-ID: <20120815152449.GF25473@momjian.us> References: <201108141125.p7EBPMBS044920@wwwmaster.postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Y7xTucakfITjPcLV" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <201108141125.p7EBPMBS044920@wwwmaster.postgresql.org> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/101 X-Sequence-Number: 33825 --Y7xTucakfITjPcLV Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Sun, Aug 14, 2011 at 11:25:22AM +0000, Emmanuel Guyot wrote: > > The following bug has been logged online: > > Bug reference: 6162 > Logged by: Emmanuel Guyot > Email address: emmanuel.guyot@gmail.com > PostgreSQL version: 8.2.3 > Operating system: Windows 7 > Description: initdb : Windows username isn't escaped > Details: > > Initdb crashes when I use it with a windows username that has a quote inside > (e.g. : L'élixir) > > Here is the error reported : > initialisation des droits sur les objets internes... 2010-05-14 17:01:25.434 > FATAL: syntax error at or near "élixir" at character 44 > 2010-05-14 17:01:25.434 STATEMENT: UPDATE pg_class SET relacl = > E'{"=r/\\"L'élixir\\""}' WHERE relkind IN ('r', 'v', 'S') AND relacl IS > NULL; > > If I force the username as an option with the escaped value L\'élixir the > initdb works fine, but I can't start the server. So I can't find a > workaround. > > I've watched the newer sources of initdb and I can't see any change for this > bug. I have fixed the problem with the attached, applied patch, which will appear in Postgres 9.3. The problem was that single-quotes in usernames were not properly escaped by initdb. Also, I have improved the pg_hba.conf documentation, and added an assert to catch future breakage. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + --Y7xTucakfITjPcLV Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="initdb.diff" diff --git a/doc/src/sgml/client-auth.sgml b/doc/src/sgml/client-auth.sgml new file mode 100644 index 679c40a..9771394 *** a/doc/src/sgml/client-auth.sgml --- b/doc/src/sgml/client-auth.sgml *************** *** 80,86 **** Records cannot be continued across lines. A record is made up of a number of fields which are separated by spaces and/or tabs. ! Fields can contain white space if the field value is quoted. Quoting one of the keywords in a database, user, or address field (e.g., all or replication) makes the word lose its special character, and just match a database, user, or host with that name. --- 80,86 ---- Records cannot be continued across lines. A record is made up of a number of fields which are separated by spaces and/or tabs. ! Fields can contain white space if the field value is double-quoted. Quoting one of the keywords in a database, user, or address field (e.g., all or replication) makes the word lose its special character, and just match a database, user, or host with that name. diff --git a/src/backend/parser/scansup.c b/src/backend/parser/scansup.c new file mode 100644 index 6101457..b8e2f71 *** a/src/backend/parser/scansup.c --- b/src/backend/parser/scansup.c *************** scanstr(const char *s) *** 56,61 **** --- 56,63 ---- * 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 new file mode 100644 index 132ad0f..a53760a *** a/src/bin/initdb/initdb.c --- b/src/bin/initdb/initdb.c *************** bootstrap_template1(void) *** 1395,1401 **** bki_lines = replace_token(bki_lines, "FLOAT8PASSBYVAL", FLOAT8PASSBYVAL ? "true" : "false"); ! bki_lines = replace_token(bki_lines, "POSTGRES", username); bki_lines = replace_token(bki_lines, "ENCODING", encodingid); --- 1395,1401 ---- bki_lines = replace_token(bki_lines, "FLOAT8PASSBYVAL", FLOAT8PASSBYVAL ? "true" : "false"); ! bki_lines = replace_token(bki_lines, "POSTGRES", escape_quotes(username)); bki_lines = replace_token(bki_lines, "ENCODING", encodingid); *************** setup_privileges(void) *** 2043,2050 **** PG_CMD_OPEN; ! priv_lines = replace_token(privileges_setup, ! "$POSTGRES_SUPERUSERNAME", username); for (line = priv_lines; *line != NULL; line++) PG_CMD_PUTS(*line); --- 2043,2050 ---- PG_CMD_OPEN; ! priv_lines = replace_token(privileges_setup, "$POSTGRES_SUPERUSERNAME", ! escape_quotes(username)); for (line = priv_lines; *line != NULL; line++) PG_CMD_PUTS(*line); *************** main(int argc, char *argv[]) *** 3056,3062 **** 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. --- 3056,3061 ---- --Y7xTucakfITjPcLV--