aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-16 20:46:15 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-16 20:46:15 +0100
commitcb18b546f7ee9d1c9315c7357ab620e55f0fa8f3 (patch)
tree35f1cc57b6ec62af95b893c8379baac155cf0a7e
parent2e8be023cbd96c54256b5908837039100dc4fc45 (diff)
downloadbusybox-w32-cb18b546f7ee9d1c9315c7357ab620e55f0fa8f3.tar.gz
busybox-w32-cb18b546f7ee9d1c9315c7357ab620e55f0fa8f3.tar.bz2
busybox-w32-cb18b546f7ee9d1c9315c7357ab620e55f0fa8f3.zip
bc: disallow empty statement as function body
$ bc define z() <cr> <cr> bc: no statement after 'define' function old new delta zbc_parse_stmt_possibly_auto 2239 2245 +6 zbc_vm_process 589 594 +5 zbc_parse_stmt_fail_if_bare_NLINE 25 28 +3 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 14/0) Total: 14 bytes text data bss dec hex filename 982216 485 7296 989997 f1b2d busybox_old 982237 485 7296 990018 f1b42 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index ed2497c4c..2dc64dbc6 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -3677,14 +3677,14 @@ static BC_STATUS zbc_parse_stmt(BcParse *p)
3677# define zbc_parse_stmt(...) (zbc_parse_stmt(__VA_ARGS__), BC_STATUS_SUCCESS) 3677# define zbc_parse_stmt(...) (zbc_parse_stmt(__VA_ARGS__), BC_STATUS_SUCCESS)
3678#endif 3678#endif
3679 3679
3680static BC_STATUS zbc_parse_stmt_fail_if_bare_NLINE(BcParse *p, const char *after_X) 3680static BC_STATUS zbc_parse_stmt_fail_if_bare_NLINE(BcParse *p, bool auto_allowed, const char *after_X)
3681{ 3681{
3682 if (p->l.t.t == BC_LEX_NLINE) 3682 if (p->l.t.t == BC_LEX_NLINE)
3683 RETURN_STATUS(bc_error_fmt("no statement after '%s'", after_X)); 3683 RETURN_STATUS(bc_error_fmt("no statement after '%s'", after_X));
3684 RETURN_STATUS(zbc_parse_stmt(p)); 3684 RETURN_STATUS(zbc_parse_stmt_possibly_auto(p, auto_allowed));
3685} 3685}
3686#if ERRORS_ARE_FATAL 3686#if ERRORS_ARE_FATAL
3687# define zbc_parse_stmt_fail_if_bare_NLINE((...) (zbc_parse_stmt_fail_if_bare_NLINE((__VA_ARGS__), BC_STATUS_SUCCESS) 3687# define zbc_parse_stmt_fail_if_bare_NLINE(...) (zbc_parse_stmt_fail_if_bare_NLINE(__VA_ARGS__), BC_STATUS_SUCCESS)
3688#endif 3688#endif
3689 3689
3690static void bc_parse_operator(BcParse *p, BcLexType type, size_t start, 3690static void bc_parse_operator(BcParse *p, BcLexType type, size_t start,
@@ -4151,7 +4151,7 @@ static BC_STATUS zbc_parse_if(BcParse *p)
4151 bc_vec_push(&p->exits, &ip); 4151 bc_vec_push(&p->exits, &ip);
4152 bc_vec_push(&p->func->labels, &ip.idx); 4152 bc_vec_push(&p->func->labels, &ip.idx);
4153 4153
4154 s = zbc_parse_stmt_fail_if_bare_NLINE(p, "if"); 4154 s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "if");
4155 if (s) RETURN_STATUS(s); 4155 if (s) RETURN_STATUS(s);
4156 4156
4157 dbg_lex("%s:%d in if after stmt: p->l.t.t:%d", __func__, __LINE__, p->l.t.t); 4157 dbg_lex("%s:%d in if after stmt: p->l.t.t:%d", __func__, __LINE__, p->l.t.t);
@@ -4230,7 +4230,7 @@ static BC_STATUS zbc_parse_while(BcParse *p)
4230 bc_parse_push(p, BC_INST_JUMP_ZERO); 4230 bc_parse_push(p, BC_INST_JUMP_ZERO);
4231 bc_parse_pushIndex(p, ip.idx); 4231 bc_parse_pushIndex(p, ip.idx);
4232 4232
4233 s = zbc_parse_stmt_fail_if_bare_NLINE(p, "while"); 4233 s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "while");
4234 if (s) RETURN_STATUS(s); 4234 if (s) RETURN_STATUS(s);
4235 4235
4236 n = *((size_t *) bc_vec_top(&p->conds)); 4236 n = *((size_t *) bc_vec_top(&p->conds));
@@ -4334,7 +4334,7 @@ static BC_STATUS zbc_parse_for(BcParse *p)
4334 s = zbc_lex_next_and_skip_NLINE(&p->l); 4334 s = zbc_lex_next_and_skip_NLINE(&p->l);
4335 if (s) RETURN_STATUS(s); 4335 if (s) RETURN_STATUS(s);
4336 4336
4337 s = zbc_parse_stmt_fail_if_bare_NLINE(p, "for"); 4337 s = zbc_parse_stmt_fail_if_bare_NLINE(p, false, "for");
4338 if (s) RETURN_STATUS(s); 4338 if (s) RETURN_STATUS(s);
4339 4339
4340 n = *((size_t *) bc_vec_top(&p->conds)); 4340 n = *((size_t *) bc_vec_top(&p->conds));
@@ -4468,7 +4468,7 @@ static BC_STATUS zbc_parse_funcdef(BcParse *p)
4468//TODO: GNU bc requires a {} block even if function body has single stmt, enforce this? 4468//TODO: GNU bc requires a {} block even if function body has single stmt, enforce this?
4469 4469
4470 p->in_funcdef++; // to determine whether "return" stmt is allowed, and such 4470 p->in_funcdef++; // to determine whether "return" stmt is allowed, and such
4471 s = zbc_parse_stmt_possibly_auto(p, true); 4471 s = zbc_parse_stmt_fail_if_bare_NLINE(p, true, "define");
4472 p->in_funcdef--; 4472 p->in_funcdef--;
4473 if (s) RETURN_STATUS(s); 4473 if (s) RETURN_STATUS(s);
4474 4474