mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-23 09:10:40 +02:00
Disallow a digit as the first character of a variable name in pgbench.
The point of this restriction is to avoid trying to substitute variables
into timestamp literal values, which may contain strings like '12:34'.
There is a good deal more that should be done to reduce pgbench's
tendency to substitute where it shouldn't. But this is sufficient to
solve the case complained of by Jaime Soler, and it's simple enough
to back-patch.
Back-patch to v11; before commit 9d36a3866
, pgbench had a slightly
different definition of what a variable name is, and anyway it seems
unwise to change long-stable branches for this.
Fabien Coelho
Discussion: https://postgr.es/m/alpine.DEB.2.22.394.2006291740420.805678@pseudo
This commit is contained in:
parent
bcdff44914
commit
d8bb22ab3c
@ -899,7 +899,7 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
|
|||||||
<para>
|
<para>
|
||||||
There is a simple variable-substitution facility for script files.
|
There is a simple variable-substitution facility for script files.
|
||||||
Variable names must consist of letters (including non-Latin letters),
|
Variable names must consist of letters (including non-Latin letters),
|
||||||
digits, and underscores.
|
digits, and underscores, with the first character not being a digit.
|
||||||
Variables can be set by the command-line <option>-D</option> option,
|
Variables can be set by the command-line <option>-D</option> option,
|
||||||
explained above, or by the meta commands explained below.
|
explained above, or by the meta commands explained below.
|
||||||
In addition to any variables preset by <option>-D</option> command-line options,
|
In addition to any variables preset by <option>-D</option> command-line options,
|
||||||
|
@ -1322,6 +1322,7 @@ makeVariableValue(Variable *var)
|
|||||||
* "src/bin/pgbench/exprscan.l". Also see parseVariable(), below.
|
* "src/bin/pgbench/exprscan.l". Also see parseVariable(), below.
|
||||||
*
|
*
|
||||||
* Note: this static function is copied from "src/bin/psql/variables.c"
|
* Note: this static function is copied from "src/bin/psql/variables.c"
|
||||||
|
* but changed to disallow variable names starting with a digit.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
valid_variable_name(const char *name)
|
valid_variable_name(const char *name)
|
||||||
@ -1332,6 +1333,15 @@ valid_variable_name(const char *name)
|
|||||||
if (*ptr == '\0')
|
if (*ptr == '\0')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
/* must not start with [0-9] */
|
||||||
|
if (IS_HIGHBIT_SET(*ptr) ||
|
||||||
|
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
|
||||||
|
"_", *ptr) != NULL)
|
||||||
|
ptr++;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* remaining characters can include [0-9] */
|
||||||
while (*ptr)
|
while (*ptr)
|
||||||
{
|
{
|
||||||
if (IS_HIGHBIT_SET(*ptr) ||
|
if (IS_HIGHBIT_SET(*ptr) ||
|
||||||
@ -1453,23 +1463,27 @@ putVariableInt(CState *st, const char *context, char *name, int64 value)
|
|||||||
*
|
*
|
||||||
* "sql" points at a colon. If what follows it looks like a valid
|
* "sql" points at a colon. If what follows it looks like a valid
|
||||||
* variable name, return a malloc'd string containing the variable name,
|
* variable name, return a malloc'd string containing the variable name,
|
||||||
* and set *eaten to the number of characters consumed.
|
* and set *eaten to the number of characters consumed (including the colon).
|
||||||
* Otherwise, return NULL.
|
* Otherwise, return NULL.
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
parseVariable(const char *sql, int *eaten)
|
parseVariable(const char *sql, int *eaten)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 1; /* starting at 1 skips the colon */
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
do
|
/* keep this logic in sync with valid_variable_name() */
|
||||||
{
|
if (IS_HIGHBIT_SET(sql[i]) ||
|
||||||
i++;
|
|
||||||
} while (IS_HIGHBIT_SET(sql[i]) ||
|
|
||||||
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
|
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
|
||||||
"_0123456789", sql[i]) != NULL);
|
"_", sql[i]) != NULL)
|
||||||
if (i == 1)
|
i++;
|
||||||
return NULL; /* no valid variable name chars */
|
else
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
while (IS_HIGHBIT_SET(sql[i]) ||
|
||||||
|
strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"
|
||||||
|
"_0123456789", sql[i]) != NULL)
|
||||||
|
i++;
|
||||||
|
|
||||||
name = pg_malloc(i);
|
name = pg_malloc(i);
|
||||||
memcpy(name, &sql[1], i - 1);
|
memcpy(name, &sql[1], i - 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user