v02_pgbench_sleep.patch
text/x-diff
Filename: v02_pgbench_sleep.patch
Type: text/x-diff
Part: 0
Patch
Format: unified
Series: patch v2
| File | + | − |
|---|---|---|
| src/bin/pgbench/pgbench.c | 25 | 4 |
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index f1d98be2d2..822461dce6 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -2861,7 +2861,18 @@ evaluateSleep(CState *st, int argc, char **argv, int *usecs)
pg_log_error("%s: undefined variable \"%s\"", argv[0], argv[1] + 1);
return false;
}
+
+ for (int i = 0; i < strlen(var); i++)
+ {
+ if(!isdigit(var[i]))
+ {
+ pg_log_error("\\sleep command argument must be an integer (not \"%s\")", var);
+ return false;
+ }
+ }
+
usec = atoi(var);
+
}
else
usec = atoi(argv[1]);
@@ -4648,7 +4659,7 @@ process_backslash_command(PsqlScanState sstate, const char *source)
* will be parsed with atoi, which ignores trailing non-digit
* characters.
*/
- if (my_command->argc == 2 && my_command->argv[1][0] != ':')
+ if (my_command->argv[1][0] != ':')
{
char *c = my_command->argv[1];
@@ -4656,9 +4667,19 @@ process_backslash_command(PsqlScanState sstate, const char *source)
c++;
if (*c)
{
- my_command->argv[2] = c;
- offsets[2] = offsets[1] + (c - my_command->argv[1]);
- my_command->argc = 3;
+ /* Raise an error if argv[1] does not start with a number */
+ if (my_command->argc == 2 && my_command->argv[1] != c)
+ {
+ my_command->argv[2] = c;
+ offsets[2] = offsets[1] + (c - my_command->argv[1]);
+ my_command->argc = 3;
+ }
+ else
+ {
+ syntax_error(source, lineno, my_command->first_line, my_command->argv[0],
+ "\\sleep command argument must be an integer",
+ my_command->argv[1], offsets[1] - start_offset);
+ }
}
}