Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gdfkz-0002Ql-28 for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Dec 2018 18:24:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gdfkv-0002BW-O3 for pgsql-hackers@arkaria.postgresql.org; Sun, 30 Dec 2018 18:24:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gdfkv-0002BP-Gq for pgsql-hackers@lists.postgresql.org; Sun, 30 Dec 2018 18:24:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gdfks-0003pi-8E for pgsql-hackers@lists.postgresql.org; Sun, 30 Dec 2018 18:24:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wBUIO22i031043; Sun, 30 Dec 2018 13:24:02 -0500 From: Tom Lane To: pgsql-hackers@lists.postgresql.org cc: Stephen Frost Subject: Is MinMaxExpr really leakproof? MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31041.1546194242.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 30 Dec 2018 13:24:02 -0500 Message-ID: <31042.1546194242@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk contain_leaked_vars_walker asserts the following about MinMaxExpr: ... case T_MinMaxExpr: ... /* * We know these node types don't contain function calls; but * something further down in the node tree might. */ break; Now, the idea that it "doesn't contain a function call" is nonsense, because the node will invoke the btree comparison function for the datatype of its arguments. So this coding amounts to an undocumented assumption that every non-cross-type btree comparison function is leakproof. A quick catalog query finds 15 counterexamples just among the built-in datatypes: select p.oid::regprocedure from pg_proc p, pg_amproc a, pg_opfamily f where p.oid=3Da.amproc and f.oid=3Da.amprocfamily and opfmethod=3D403 and = not proleakproof and amproclefttype=3Damprocrighttype and amprocnum=3D1; bpcharcmp(character,character) btarraycmp(anyarray,anyarray) btbpchar_pattern_cmp(character,character) btoidvectorcmp(oidvector,oidvector) btrecordcmp(record,record) btrecordimagecmp(record,record) bttext_pattern_cmp(text,text) bttextcmp(text,text) enum_cmp(anyenum,anyenum) jsonb_cmp(jsonb,jsonb) numeric_cmp(numeric,numeric) pg_lsn_cmp(pg_lsn,pg_lsn) range_cmp(anyrange,anyrange) tsquery_cmp(tsquery,tsquery) tsvector_cmp(tsvector,tsvector) so this assumption is, on its face, wrong. In practice it might be all right, because it's hard to see a reason why a btree comparison function would ever throw an error except for internal failures, which are probably outside the scope of leakproofness guarantees anyway. Nonetheless, if we didn't mark these functions as leakproof, why not? I think that we should either change contain_leaked_vars_walker to explicitly verify leakproofness of the comparison function, or decide that it's project policy that btree comparison functions are leakproof, and change the markings on those (and their associated operators). regards, tom lane