Quoting issues with createdb
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Date: 2020-02-14T04:10:04Z
Lists: pgsql-hackers
Attachments
- createdb-quotes-v1.patch (text/x-diff) patch v1
Hi all, createdb has a couple of issues with its quoting. For example take that, which can be confusing: $ createdb --lc-ctype="en_US.UTF-8';create table aa();select '1" popo createdb: error: database creation failed: ERROR: CREATE DATABASE cannot run inside a transaction block The root of the issue is that any values added by the command caller with --lc-collate, --lc-ctype or --encoding are not quoted properly, and in all three cases it means that the quoting needs to be encoding-sensitive (Tom mentioned me directly that part). This proper quoting can be achieved using appendStringLiteralConn() from string_utils.c, at the condition of taking the connection to the server before building the CREATE DATABASE query. Note that for --encoding, this is less of a problem as there is some extra validation with pg_char_to_encoding(), but it seems better to me to be consistent. So this gives the patch attached, where the error becomes: ERROR: invalid locale name: "en_US.UTF-8';create table aa();select '1" Any opinions? -- Michael
Commits
-
createdb: Fix quoting of --encoding, --lc-ctype and --lc-collate
- 49300e4cf2da 9.5.22 landed
- 3340034f2c19 9.6.18 landed
- 240c7c75f3a9 10.13 landed
- 83bd732eb2c8 11.8 landed
- 943affb3d1db 12.3 landed
- 008cf040962c 13.0 landed