Commit 3db826bd authored by Tom Lane's avatar Tom Lane

Tighten up allowed names for custom GUC parameters.

Formerly we were pretty lax about what a custom GUC's name could
be; so long as it had at least one dot in it, we'd take it.
However, corner cases such as dashes or equal signs in the name
would cause various bits of functionality to misbehave.  Rather
than trying to make the world perfectly safe for that, let's
just require that custom names look like "identifier.identifier",
where "identifier" means something that scan.l would accept
without double quotes.

Along the way, this patch refactors things slightly in guc.c
so that find_option() is responsible for reporting GUC-not-found
cases, allowing removal of duplicative code from its callers.

Per report from Hubert Depesz Lubaczewski.  No back-patch,
since the consequences of the problem don't seem to warrant
changing behavior in stable branches.

Discussion: https://postgr.es/m/951335.1612910077@sss.pgh.pa.us
parent 23607a81
......@@ -282,7 +282,7 @@ ProcessConfigFileInternal(GucContext context, bool applySettings, int elevel)
* Try to find the variable; but do not create a custom placeholder if
* it's not there already.
*/
record = find_option(item->name, false, elevel);
record = find_option(item->name, false, true, elevel);
if (record)
{
......@@ -306,7 +306,7 @@ ProcessConfigFileInternal(GucContext context, bool applySettings, int elevel)
/* Now mark it as present in file */
record->status |= GUC_IS_IN_FILE;
}
else if (strchr(item->name, GUC_QUALIFIER_SEPARATOR) == NULL)
else if (!valid_custom_variable_name(item->name))
{
/* Invalid non-custom variable, so complain */
ereport(elevel,
......
This diff is collapsed.
......@@ -511,6 +511,27 @@ SET seq_page_cost TO 'NaN';
ERROR: invalid value for parameter "seq_page_cost": "NaN"
SET vacuum_cost_delay TO '10s';
ERROR: 10000 ms is outside the valid range for parameter "vacuum_cost_delay" (0 .. 100)
SET no_such_variable TO 42;
ERROR: unrecognized configuration parameter "no_such_variable"
-- Test "custom" GUCs created on the fly (which aren't really an
-- intended feature, but many people use them).
SET custom.my_guc = 42;
SHOW custom.my_guc;
custom.my_guc
---------------
42
(1 row)
SET custom."bad-guc" = 42; -- disallowed because -c cannot set this name
ERROR: invalid configuration parameter name "custom.bad-guc"
DETAIL: Custom parameter names must be of the form "identifier.identifier".
SHOW custom."bad-guc";
ERROR: unrecognized configuration parameter "custom.bad-guc"
SET special."weird name" = 'foo'; -- could be allowed, but we choose not to
ERROR: invalid configuration parameter name "special.weird name"
DETAIL: Custom parameter names must be of the form "identifier.identifier".
SHOW special."weird name";
ERROR: unrecognized configuration parameter "special.weird name"
--
-- Test DISCARD TEMP
--
......
......@@ -147,6 +147,16 @@ SELECT '2006-08-13 12:34:56'::timestamptz;
-- Test some simple error cases
SET seq_page_cost TO 'NaN';
SET vacuum_cost_delay TO '10s';
SET no_such_variable TO 42;
-- Test "custom" GUCs created on the fly (which aren't really an
-- intended feature, but many people use them).
SET custom.my_guc = 42;
SHOW custom.my_guc;
SET custom."bad-guc" = 42; -- disallowed because -c cannot set this name
SHOW custom."bad-guc";
SET special."weird name" = 'foo'; -- could be allowed, but we choose not to
SHOW special."weird name";
--
-- Test DISCARD TEMP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment