Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c1Hn9-00012O-FL for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Oct 2016 18:58:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1c1Hn9-0000mL-0i for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Oct 2016 18:58:43 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c1Hlg-0007Wx-1u for pgsql-hackers@postgreSQL.org; Mon, 31 Oct 2016 18:57:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1c1Hld-0001dh-7W for pgsql-hackers@postgreSQL.org; Mon, 31 Oct 2016 18:57:11 +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 u9VIv762026682 for ; Mon, 31 Oct 2016 14:57:07 -0400 From: Tom Lane To: pgsql-hackers@postgreSQL.org Subject: Unsafe use of relation->rd_options without checking its type MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26680.1477940227.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 31 Oct 2016 14:57:07 -0400 Message-ID: <26681.1477940227@sss.pgh.pa.us> X-Pg-Spam-Score: -4.6 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org I looked into bug#14397. The submitter was discourteous enough not to provide an in-line example, but here it is: CREATE TABLE IF NOT EXISTS TEST_1 ( ID SERIAL PRIMARY KEY, C1 BYTEA, C2 TEXT NOT NULL, C3 BOOLEAN NOT NULL DEFAULT FALSE, CONSTRAINT TEST_1_unique_idx UNIQUE(C1, C2) create or replace view test as select * from test_1 with cascaded check opt= ion; insert into test (c1, c2, c3) values (decode('MTIzAAE=3D', 'base64'), 'text', true) on conflict (c1, c2) do update set c3=3Dexcluded.c3; ERROR: ON CONFLICT is not supported on table "test" used as a catalog table LINE 1: ...lues (decode('MTIzAAE=3D', 'base64'), 'text', true) on conflic... ^ The reason for the error is that transformOnConflictArbiter applies RelationIsUsedAsCatalogTable() to something that it doesn't know to be a plain relation --- it's a view in this case. And that macro blindly assumes that relation->rd_options is a StdRdOptions struct, when in this case it's actually a ViewOptions struct. Now that I've seen this I wonder which other uses of rd_options are potentially broken. RelationIsUsedAsCatalogTable() is hardly the only macro that is assuming with little justification that it's applied to the right kind of reloptions. We could band-aid this by having the RelationIsUsedAsCatalogTable() macro check relation->relkind, but I'm inclined to think that the right fix going forward is to insist that StdRdOptions, ViewOptions, and the other in-memory representations of reloptions ought to be self-identifying somehow. We could add a field to them similar to nodeTag, but one of the things that was envisioned to begin with is relation types that have StdRdOptions as the first part of a larger struct. I'm not sure how to make that work with a tag. Thoughts? regards, tom lane --=20 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers