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

Commit3e214fa

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 parent0363b7e commit3e214fa

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
@@ -942,7 +942,7 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
942942
<para>
943943
There is a simple variable-substitution facility for script files.
944944
Variable names must consist of letters (including non-Latin letters),
945-
digits, and underscores.
945+
digits, and underscores, with the first character not being a digit.
946946
Variables can be set by the command-line <option>-D</option> option,
947947
explained above, or by the meta commands explained below.
948948
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
@@ -1356,6 +1356,7 @@ makeVariableValue(Variable *var)
13561356
* "src/bin/pgbench/exprscan.l". Also see parseVariable(), below.
13571357
*
13581358
* Note: this static function is copied from "src/bin/psql/variables.c"
1359+
* but changed to disallow variable names starting with a digit.
13591360
*/
13601361
staticbool
13611362
valid_variable_name(constchar*name)
@@ -1366,6 +1367,15 @@ valid_variable_name(const char *name)
13661367
if (*ptr=='\0')
13671368
return false;
13681369

1370+
/* must not start with [0-9] */
1371+
if (IS_HIGHBIT_SET(*ptr)||
1372+
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ""abcdefghijklmnopqrstuvwxyz"
1373+
"_",*ptr)!=NULL)
1374+
ptr++;
1375+
else
1376+
return false;
1377+
1378+
/* remaining characters can include [0-9] */
13691379
while (*ptr)
13701380
{
13711381
if (IS_HIGHBIT_SET(*ptr)||
@@ -1487,23 +1497,27 @@ putVariableInt(CState *st, const char *context, char *name, int64 value)
14871497
*
14881498
* "sql" points at a colon. If what follows it looks like a valid
14891499
* variable name, return a malloc'd string containing the variable name,
1490-
* and set *eaten to the number of characters consumed.
1500+
* and set *eaten to the number of characters consumed (including the colon).
14911501
* Otherwise, return NULL.
14921502
*/
14931503
staticchar*
14941504
parseVariable(constchar*sql,int*eaten)
14951505
{
1496-
inti=0;
1506+
inti=1;/* starting at 1 skips the colon */
14971507
char*name;
14981508

1499-
do
1500-
{
1509+
/* keep this logic in sync with valid_variable_name() */
1510+
if (IS_HIGHBIT_SET(sql[i])||
1511+
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ""abcdefghijklmnopqrstuvwxyz"
1512+
"_",sql[i])!=NULL)
1513+
i++;
1514+
else
1515+
returnNULL;
1516+
1517+
while (IS_HIGHBIT_SET(sql[i])||
1518+
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ""abcdefghijklmnopqrstuvwxyz"
1519+
"_0123456789",sql[i])!=NULL)
15011520
i++;
1502-
}while (IS_HIGHBIT_SET(sql[i])||
1503-
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ""abcdefghijklmnopqrstuvwxyz"
1504-
"_0123456789",sql[i])!=NULL);
1505-
if (i==1)
1506-
returnNULL;/* no valid variable name chars */
15071521

15081522
name=pg_malloc(i);
15091523
memcpy(name,&sql[1],i-1);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp