Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6b045ca

Browse files
committed
Disallow a digit as the first character of a variable name in pgbench.
The point of this restriction is to avoid trying to substitute variablesinto timestamp literal values, which may contain strings like '12:34'.There is a good deal more that should be done to reduce pgbench'stendency to substitute where it shouldn't. But this is sufficient tosolve the case complained of by Jaime Soler, and it's simple enoughto back-patch.Back-patch to v11; before commit9d36a38, pgbench had a slightlydifferent definition of what a variable name is, and anyway it seemsunwise to change long-stable branches for this.Fabien CoelhoDiscussion:https://postgr.es/m/alpine.DEB.2.22.394.2006291740420.805678@pseudo
1 parentc77f311 commit6b045ca

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

‎doc/src/sgml/ref/pgbench.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
10081008
<para>
10091009
There is a simple variable-substitution facility for script files.
10101010
Variable names must consist of letters (including non-Latin letters),
1011-
digits, and underscores.
1011+
digits, and underscores, with the first character not being a digit.
10121012
Variables can be set by the command-line <option>-D</option> option,
10131013
explained above, or by the meta commands explained below.
10141014
In addition to any variables preset by <option>-D</option> command-line options,

‎src/bin/pgbench/pgbench.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ makeVariableValue(Variable *var)
13771377
* "src/bin/pgbench/exprscan.l". Also see parseVariable(), below.
13781378
*
13791379
* Note: this static function is copied from "src/bin/psql/variables.c"
1380+
* but changed to disallow variable names starting with a digit.
13801381
*/
13811382
staticbool
13821383
valid_variable_name(constchar*name)
@@ -1387,6 +1388,15 @@ valid_variable_name(const char *name)
13871388
if (*ptr=='\0')
13881389
return false;
13891390

1391+
/* must not start with [0-9] */
1392+
if (IS_HIGHBIT_SET(*ptr)||
1393+
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ""abcdefghijklmnopqrstuvwxyz"
1394+
"_",*ptr)!=NULL)
1395+
ptr++;
1396+
else
1397+
return false;
1398+
1399+
/* remaining characters can include [0-9] */
13901400
while (*ptr)
13911401
{
13921402
if (IS_HIGHBIT_SET(*ptr)||
@@ -1507,23 +1517,27 @@ putVariableInt(CState *st, const char *context, char *name, int64 value)
15071517
*
15081518
* "sql" points at a colon. If what follows it looks like a valid
15091519
* variable name, return a malloc'd string containing the variable name,
1510-
* and set *eaten to the number of characters consumed.
1520+
* and set *eaten to the number of characters consumed (including the colon).
15111521
* Otherwise, return NULL.
15121522
*/
15131523
staticchar*
15141524
parseVariable(constchar*sql,int*eaten)
15151525
{
1516-
inti=0;
1526+
inti=1;/* starting at 1 skips the colon */
15171527
char*name;
15181528

1519-
do
1520-
{
1529+
/* keep this logic in sync with valid_variable_name() */
1530+
if (IS_HIGHBIT_SET(sql[i])||
1531+
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ""abcdefghijklmnopqrstuvwxyz"
1532+
"_",sql[i])!=NULL)
1533+
i++;
1534+
else
1535+
returnNULL;
1536+
1537+
while (IS_HIGHBIT_SET(sql[i])||
1538+
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ""abcdefghijklmnopqrstuvwxyz"
1539+
"_0123456789",sql[i])!=NULL)
15211540
i++;
1522-
}while (IS_HIGHBIT_SET(sql[i])||
1523-
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ""abcdefghijklmnopqrstuvwxyz"
1524-
"_0123456789",sql[i])!=NULL);
1525-
if (i==1)
1526-
returnNULL;/* no valid variable name chars */
15271541

15281542
name=pg_malloc(i);
15291543
memcpy(name,&sql[1],i-1);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp