summaryrefslogtreecommitdiff
path: root/src/bin/pgbench/pgbench.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2024-12-15 14:14:15 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2024-12-15 14:14:15 -0500
commitec0dc2c596ff7c950ea3d47bf0994ef0e322ceb7 (patch)
treeb4d4ba062c0153bfadd5bc0ed4b4de49f17ae4d2 /src/bin/pgbench/pgbench.c
parentb6df2d6e5d83e6204bcb74977c12d4ccbf18e8cd (diff)
pgbench: fix misprocessing of some nested \if constructs.
An \if command appearing within a false (not-to-be-executed) \if branch was incorrectly treated the same as \elif. This could allow statements within the inner \if to be executed when they should not be. Also the missing inner \if stack entry would result in an assertion failure (in assert-enabled builds) when the final \endif is reached. Report and patch by Michail Nikolaev. Back-patch to all supported branches. Discussion: https://postgr.es/m/CANtu0oiA1ke=SP6tauhNqkUdv5QFsJtS1p=aOOf_iU+EhyKkjQ@mail.gmail.com
Diffstat (limited to 'src/bin/pgbench/pgbench.c')
-rw-r--r--src/bin/pgbench/pgbench.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 6bccacaf86c..ed301e120c4 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -3133,8 +3133,14 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
switch (conditional_stack_peek(st->cstack))
{
case IFSTATE_FALSE:
- if (command->meta == META_IF ||
- command->meta == META_ELIF)
+ if (command->meta == META_IF)
+ {
+ /* nested if in skipped branch - ignore */
+ conditional_stack_push(st->cstack,
+ IFSTATE_IGNORED);
+ st->command++;
+ }
+ else if (command->meta == META_ELIF)
{
/* we must evaluate the condition */
st->state = CSTATE_START_COMMAND;
@@ -3153,11 +3159,7 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
conditional_stack_pop(st->cstack);
if (conditional_active(st->cstack))
st->state = CSTATE_START_COMMAND;
-
- /*
- * else state remains in
- * CSTATE_SKIP_COMMAND
- */
+ /* else state remains CSTATE_SKIP_COMMAND */
st->command++;
}
break;