diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-07-14 14:33:37 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-07-14 16:32:19 +0200 |
| commit | d3480dd58211d9d8c06ec7ef00089262603003ff (patch) | |
| tree | 447a49b67af1f714bf725065469c697e810300c7 | |
| parent | d62627487a44d9175b05d49846aeef83fed97019 (diff) | |
| download | busybox-w32-d3480dd58211d9d8c06ec7ef00089262603003ff.tar.gz busybox-w32-d3480dd58211d9d8c06ec7ef00089262603003ff.tar.bz2 busybox-w32-d3480dd58211d9d8c06ec7ef00089262603003ff.zip | |
awk: disallow break/continue outside of loops
function old new delta
.rodata 104139 104186 +47
chain_group 610 633 +23
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 70/0) Total: 70 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | editors/awk.c | 6 | ||||
| -rwxr-xr-x | testsuite/awk.tests | 9 |
2 files changed, 6 insertions, 9 deletions
diff --git a/editors/awk.c b/editors/awk.c index 2f8a18c8e..607d69487 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
| @@ -1671,16 +1671,18 @@ static void chain_group(void) | |||
| 1671 | case OC_BREAK: | 1671 | case OC_BREAK: |
| 1672 | debug_printf_parse("%s: OC_BREAK\n", __func__); | 1672 | debug_printf_parse("%s: OC_BREAK\n", __func__); |
| 1673 | n = chain_node(OC_EXEC); | 1673 | n = chain_node(OC_EXEC); |
| 1674 | if (!break_ptr) | ||
| 1675 | syntax_error("'break' not in a loop"); | ||
| 1674 | n->a.n = break_ptr; | 1676 | n->a.n = break_ptr; |
| 1675 | //TODO: if break_ptr is NULL, syntax error (not in the loop)? | ||
| 1676 | chain_expr(t_info); | 1677 | chain_expr(t_info); |
| 1677 | break; | 1678 | break; |
| 1678 | 1679 | ||
| 1679 | case OC_CONTINUE: | 1680 | case OC_CONTINUE: |
| 1680 | debug_printf_parse("%s: OC_CONTINUE\n", __func__); | 1681 | debug_printf_parse("%s: OC_CONTINUE\n", __func__); |
| 1681 | n = chain_node(OC_EXEC); | 1682 | n = chain_node(OC_EXEC); |
| 1683 | if (!continue_ptr) | ||
| 1684 | syntax_error("'continue' not in a loop"); | ||
| 1682 | n->a.n = continue_ptr; | 1685 | n->a.n = continue_ptr; |
| 1683 | //TODO: if continue_ptr is NULL, syntax error (not in the loop)? | ||
| 1684 | chain_expr(t_info); | 1686 | chain_expr(t_info); |
| 1685 | break; | 1687 | break; |
| 1686 | 1688 | ||
diff --git a/testsuite/awk.tests b/testsuite/awk.tests index 3cddb4dd4..f53b1efe2 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests | |||
| @@ -379,19 +379,14 @@ testing "awk -e and ARGC" \ | |||
| 379 | "" | 379 | "" |
| 380 | SKIP= | 380 | SKIP= |
| 381 | 381 | ||
| 382 | # The examples are in fact not valid awk programs (break/continue | ||
| 383 | # can only be used inside loops). | ||
| 384 | # But we do accept them outside of loops. | ||
| 385 | # We had a bug with misparsing "break ; else" sequence. | ||
| 386 | # Test that *that* bug is fixed, using simplest possible scripts: | ||
| 387 | testing "awk break" \ | 382 | testing "awk break" \ |
| 388 | "awk -f - 2>&1; echo \$?" \ | 383 | "awk -f - 2>&1; echo \$?" \ |
| 389 | "0\n" \ | 384 | "awk: -:1: 'break' not in a loop\n1\n" \ |
| 390 | "" \ | 385 | "" \ |
| 391 | 'BEGIN { if (1) break; else a = 1 }' | 386 | 'BEGIN { if (1) break; else a = 1 }' |
| 392 | testing "awk continue" \ | 387 | testing "awk continue" \ |
| 393 | "awk -f - 2>&1; echo \$?" \ | 388 | "awk -f - 2>&1; echo \$?" \ |
| 394 | "0\n" \ | 389 | "awk: -:1: 'continue' not in a loop\n1\n" \ |
| 395 | "" \ | 390 | "" \ |
| 396 | 'BEGIN { if (1) continue; else a = 1 }' | 391 | 'BEGIN { if (1) continue; else a = 1 }' |
| 397 | 392 | ||
