genbki.pl not quoting keywords in postgres.bki output

From: Mark Dilger <hornschnorter(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: genbki.pl not quoting keywords in postgres.bki output
Date: 2018-05-04 19:24:27
Message-ID: 3024FC91-DB6D-4732-B31C-DF772DF039A0@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hackers,

There are not yet any examples in the postgres sources where this
oversight causes problems, but in genbki.pl, where it makes the
decision whether to quote a token:

# Quote value if needed. We need not quote values that satisfy
# the "id" pattern in bootscanner.l, currently "[-A-Za-z0-9_]+".
$bki_value = sprintf(qq'"%s"', $bki_value)
if length($bki_value) == 0
or $bki_value =~ /[^-A-Za-z0-9_]/;

it should also quote anything that is a keyword, such as "open", as
otherwise you get a syntax error during initdb.

It might be nice to quote the keywords as a defense against this in
future catalog changes in the public sources. As an example, try adding
the following:

diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat
index 66c6c224a8..d48aeb4fd3 100644
--- a/src/include/catalog/pg_proc.dat
+++ b/src/include/catalog/pg_proc.dat
@@ -10202,4 +10202,8 @@
proisstrict => 'f', prorettype => 'bool', proargtypes => 'oid int4 int4 any',
proargmodes => '{i,i,i,v}', prosrc => 'satisfies_hash_partition' },

+{ oid => '9999',
+ proname => 'open', prolang => '14', prorettype => 'bool',
+ proargtypes => 'text',
+ prosrc => 'select true' }, # prosrc doesn't matter for this example of genbki behavior
]

Perhaps you don't think that is a big enough problem to be worth
guarding against.

This patch is not that complicated, but it does create a new coding
requirement to keep bootparse.y and genbki.pl from getting out of sync.
It might be simpler to just change genbki.pl to quote everything rather
than applying this patch. I don't have an opinion on that.

mark

Attachment Content-Type Size
genbki_bootparse_keywords.patch.1 application/octet-stream 1.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2018-05-04 19:25:15 Re: Built-in connection pooling
Previous Message Robert Haas 2018-05-04 19:09:19 Re: Global snapshots