genbki.pl not quoting keywords in postgres.bki output - Mailing list pgsql-hackers

From Mark Dilger
Subject genbki.pl not quoting keywords in postgres.bki output
Date
Msg-id 3024FC91-DB6D-4732-B31C-DF772DF039A0@gmail.com
Whole thread Raw
Responses Re: genbki.pl not quoting keywords in postgres.bki output  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Global snapshots
Next
From: Robert Haas
Date:
Subject: Re: Built-in connection pooling