Skip to content

Commit 2a23dbc

Browse files
committed
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
1 parent c7f3c41 commit 2a23dbc

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3446,8 +3446,14 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
34463446
switch (conditional_stack_peek(st->cstack))
34473447
{
34483448
case IFSTATE_FALSE:
3449-
if (command->meta == META_IF ||
3450-
command->meta == META_ELIF)
3449+
if (command->meta == META_IF)
3450+
{
3451+
/* nested if in skipped branch - ignore */
3452+
conditional_stack_push(st->cstack,
3453+
IFSTATE_IGNORED);
3454+
st->command++;
3455+
}
3456+
else if (command->meta == META_ELIF)
34513457
{
34523458
/* we must evaluate the condition */
34533459
st->state = CSTATE_START_COMMAND;
@@ -3466,11 +3472,7 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
34663472
conditional_stack_pop(st->cstack);
34673473
if (conditional_active(st->cstack))
34683474
st->state = CSTATE_START_COMMAND;
3469-
3470-
/*
3471-
* else state remains in
3472-
* CSTATE_SKIP_COMMAND
3473-
*/
3475+
/* else state remains CSTATE_SKIP_COMMAND */
34743476
st->command++;
34753477
}
34763478
break;

src/bin/pgbench/t/001_pgbench_with_server.pl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,56 @@
622622
}
623623
});
624624

625+
# test nested \if constructs
626+
$node->pgbench(
627+
'--no-vacuum --client=1 --transactions=1',
628+
0,
629+
[qr{actually processed}],
630+
[qr{^$}],
631+
'nested ifs',
632+
{
633+
'pgbench_nested_if' => q(
634+
\if false
635+
SELECT 1 / 0;
636+
\if true
637+
SELECT 1 / 0;
638+
\elif true
639+
SELECT 1 / 0;
640+
\else
641+
SELECT 1 / 0;
642+
\endif
643+
SELECT 1 / 0;
644+
\elif false
645+
\if true
646+
SELECT 1 / 0;
647+
\elif true
648+
SELECT 1 / 0;
649+
\else
650+
SELECT 1 / 0;
651+
\endif
652+
\else
653+
\if false
654+
SELECT 1 / 0;
655+
\elif false
656+
SELECT 1 / 0;
657+
\else
658+
SELECT 'correct';
659+
\endif
660+
\endif
661+
\if true
662+
SELECT 'correct';
663+
\else
664+
\if true
665+
SELECT 1 / 0;
666+
\elif true
667+
SELECT 1 / 0;
668+
\else
669+
SELECT 1 / 0;
670+
\endif
671+
\endif
672+
)
673+
});
674+
625675
# random determinism when seeded
626676
$node->safe_psql('postgres',
627677
'CREATE UNLOGGED TABLE seeded_random(seed INT8 NOT NULL, rand TEXT NOT NULL, val INTEGER NOT NULL);'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy