pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17415: Unable to use underscore as first character in set_config custom parameter
3+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2022-02-23 bd74c4037c dd7c059791  Re-allow underscore as first character of custom GUC names.
* BUG #17415: Unable to use underscore as first character in set_config custom parameter
@ 2022-02-23 08:36  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2022-02-23 08:36 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: danielpolski@gmail.com

The following bug has been logged on the website:

Bug reference:      17415
Logged by:          Daniel Polski
Email address:      danielpolski@gmail.com
PostgreSQL version: 14.2
Operating system:   Linux
Description:        

SELECT set_config('_foo.bar', 'foo', FALSE);

ERROR:  invalid configuration parameter name "_foo.bar"
DETAIL:  Custom parameter names must be two or more simple identifiers
separated by dots.
SQL state: 42602

(Works in 13.5-2)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #17415: Unable to use underscore as first character in set_config custom parameter
@ 2022-02-23 13:54  Japin Li <japinli@hotmail.com>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Japin Li @ 2022-02-23 13:54 UTC (permalink / raw)
  To: danielpolski@gmail.com; pgsql-bugs@lists.postgresql.org


On Wed, 23 Feb 2022 at 16:36, PG Bug reporting form <noreply@postgresql.org> wrote:
> The following bug has been logged on the website:
>
> Bug reference:      17415
> Logged by:          Daniel Polski
> Email address:      danielpolski@gmail.com
> PostgreSQL version: 14.2
> Operating system:   Linux
> Description:        
>
> SELECT set_config('_foo.bar', 'foo', FALSE);
>
> ERROR:  invalid configuration parameter name "_foo.bar"
> DETAIL:  Custom parameter names must be two or more simple identifiers
> separated by dots.
> SQL state: 42602
>
> (Works in 13.5-2)

The following commit introduces this problem.

commit 3db826bd55cd1df0dd8c3d811f8e5b936d7ba1e4 (cusvar)
Author: Tom Lane <tgl@sss.pgh.pa.us>

    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


According to the comment of valid_custom_variable_name(), the custom variable
must be two or more identifiers separated dots, and the identifier confirm
scan.l, see below:

ident_start     [A-Za-z\200-\377_]
ident_cont      [A-Za-z\200-\377_0-9\$]

identifier      {ident_start}{ident_cont}*

However, the code in valid_custom_variable_name() doesn't confirm it.

static bool
valid_custom_variable_name(const char *name)
{
    bool        saw_sep = false;
    bool        name_start = true;

    for (const char *p = name; *p; p++)
    {
        if (*p == GUC_QUALIFIER_SEPARATOR)
        {
            if (name_start)
                return false;   /* empty name component */
            saw_sep = true;
            name_start = true;
        }
        else if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ"       <-- here forget the underscore
                        "abcdefghijklmnopqrstuvwxyz", *p) != NULL ||
                 IS_HIGHBIT_SET(*p))
        {
            /* okay as first or non-first character */
            name_start = false;
        }
        else if (!name_start && strchr("0123456789_$", *p) != NULL)
             /* okay as non-first character */ ;
        else
            return false;
    }
    if (name_start)
        return false;           /* empty name component */
    /* OK if we found at least one separator */
    return saw_sep;
}

Here is a simple patch to fix it. 

-- 
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.

Attachments:

v1-fix-underscore-as-first-char-in-custom-parameter.patch (text/x-patch, 2.0K) download diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index e4afd07bfe..e4bf1e1cd2 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -5473,14 +5473,14 @@ valid_custom_variable_name(const char *name) saw_sep = true; name_start = true; } - else if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + else if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ_" "abcdefghijklmnopqrstuvwxyz", *p) != NULL || IS_HIGHBIT_SET(*p)) { /* okay as first or non-first character */ name_start = false; } - else if (!name_start && strchr("0123456789_$", *p) != NULL) + else if (!name_start && strchr("0123456789$", *p) != NULL) /* okay as non-first character */ ; else return false; diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out index 3de6404ba5..ed17408f06 100644 --- a/src/test/regress/expected/guc.out +++ b/src/test/regress/expected/guc.out @@ -548,6 +548,13 @@ ERROR: invalid configuration parameter name "special.weird name" DETAIL: Custom parameter names must be two or more simple identifiers separated by dots. SHOW special."weird name"; ERROR: unrecognized configuration parameter "special.weird name" +SET custom._my_guc = 50; +SHOW custom._my_guc; + custom._my_guc +---------------- + 50 +(1 row) + -- Check what happens when you try to set a "custom" GUC within the -- namespace of an extension. SET plpgsql.extra_foo_warnings = true; -- allowed if plpgsql is not loaded yet diff --git a/src/test/regress/sql/guc.sql b/src/test/regress/sql/guc.sql index d5db101e48..04da5ff7a6 100644 --- a/src/test/regress/sql/guc.sql +++ b/src/test/regress/sql/guc.sql @@ -162,6 +162,8 @@ 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"; +SET custom._my_guc = 50; +SHOW custom._my_guc; -- Check what happens when you try to set a "custom" GUC within the -- namespace of an extension.
^ permalink raw reply [nested|flat] 3+ messages in thread

* Re: BUG #17415: Unable to use underscore as first character in set_config custom parameter
@ 2022-02-23 15:59  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Japin Li <japinli@hotmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2022-02-23 15:59 UTC (permalink / raw)
  To: Japin Li <japinli@hotmail.com>; +Cc: danielpolski@gmail.com; pgsql-bugs@lists.postgresql.org

Japin Li <japinli@hotmail.com> writes:
> On Wed, 23 Feb 2022 at 16:36, PG Bug reporting form <noreply@postgresql.org> wrote:
>> SELECT set_config('_foo.bar', 'foo', FALSE);
>> ERROR:  invalid configuration parameter name "_foo.bar"
>> DETAIL:  Custom parameter names must be two or more simple identifiers
>> separated by dots.

> According to the comment of valid_custom_variable_name(), the custom variable
> must be two or more identifiers separated dots, and the identifier confirm
> scan.l, see below:
> However, the code in valid_custom_variable_name() doesn't confirm it.

Yeah, it's supposed to match scan.l, so that's an embarrassing
oversight.  Will apply patch.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2022-02-23 15:59 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23 08:36 BUG #17415: Unable to use underscore as first character in set_config custom parameter PG Bug reporting form <noreply@postgresql.org>
2022-02-23 13:54 ` Japin Li <japinli@hotmail.com>
2022-02-23 15:59   ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox