Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l9WNm-0005mW-2z for pgsql-general@arkaria.postgresql.org; Tue, 09 Feb 2021 17:00:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l9WNk-0001zM-FY for pgsql-general@arkaria.postgresql.org; Tue, 09 Feb 2021 17:00:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l9WNk-0001zF-7e for pgsql-general@lists.postgresql.org; Tue, 09 Feb 2021 17:00:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l9WNd-000198-Fv for pgsql-general@postgresql.org; Tue, 09 Feb 2021 17:00:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 119H0gm9866535; Tue, 9 Feb 2021 12:00:42 -0500 From: Tom Lane To: Adrian Klaver cc: depesz@depesz.com, pgsql-general mailing list Subject: Re: How to I select value of GUC that has - in its name? In-reply-to: <0564844d-4dda-9162-13b5-4c95c4340e95@aklaver.com> References: <20210209144059.GA21360@depesz.com> <20210209154502.GA2409@depesz.com> <0564844d-4dda-9162-13b5-4c95c4340e95@aklaver.com> Comments: In-reply-to Adrian Klaver message dated "Tue, 09 Feb 2021 07:50:23 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <866533.1612890042.1@sss.pgh.pa.us> Date: Tue, 09 Feb 2021 12:00:42 -0500 Message-ID: <866534.1612890042@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver writes: > On 2/9/21 7:45 AM, hubert depesz lubaczewski wrote: >> but I find it curious that I can set the guc using normal-ish SET, but >> can't get it using SHOW or even select current_setting() > Yeah, I think that part is a bug report. After digging around in the code, I find the reason is that the entries in pg_db_role_setting.setconfig are parsed with ParseLongOption, which quoth: /* * A little "long argument" simulation, although not quite GNU * compliant. Takes a string of the form "some-option=some value" and * returns name = "some_option" and value = "some value" in malloc'ed * storage. Note that '-' is converted to '_' in the option name. If * there is no '=' in the input string then value will be NULL. */ Sure enough, regression=> show custom."bad-guc"; ERROR: unrecognized configuration parameter "custom.bad-guc" regression=> show custom."bad_guc"; custom.bad_guc ---------------- 1a (1 row) So that's where the setting went. There's a second problem here with arbitrary GUC names, which is that a name containing '=' isn't exactly gonna do what you want either. There are probably other places that are not terribly careful about funny characters in GUC names. In a quick test, I see that pg_dumpall seems to dump the ALTER USER SET safely, but I wouldn't want to bet that everything else copes. I think we should probably sanitize custom GUC names at least to the extent of forbidding '=' and '-'. Maybe we should go further and insist they look like regular identifiers. (Fortunately, ALTER USER SET with a custom GUC is superuser-only, so there's no need to worry about security issues here. But we should eliminate surprises.) regards, tom lane