diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-05 22:40:44 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-05 22:40:44 +0100 |
| commit | 050b0fe9a7b5a3e4aab1d308637ae6a3bb0a67cb (patch) | |
| tree | 139305018eaa8785ea050b086e73324ada042ff8 | |
| parent | cca79a00647ff05229265192063183677a66a4d6 (diff) | |
| download | busybox-w32-050b0fe9a7b5a3e4aab1d308637ae6a3bb0a67cb.tar.gz busybox-w32-050b0fe9a7b5a3e4aab1d308637ae6a3bb0a67cb.tar.bz2 busybox-w32-050b0fe9a7b5a3e4aab1d308637ae6a3bb0a67cb.zip | |
bc: do not allow "()" as a valid expression
function old new delta
bc_parse_expr_empty_ok - 2178 +2178
bc_parse_expr 2178 49 -2129
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/1 up/down: 2178/-2129) Total: 49 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | miscutils/bc.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index d2713ceee..eb5aff5e2 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
| @@ -3616,6 +3616,7 @@ static void bc_parse_create(BcParse *p, size_t func, | |||
| 3616 | static BcStatus bc_parse_else(BcParse *p); | 3616 | static BcStatus bc_parse_else(BcParse *p); |
| 3617 | static BcStatus bc_parse_stmt(BcParse *p); | 3617 | static BcStatus bc_parse_stmt(BcParse *p); |
| 3618 | static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next); | 3618 | static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next); |
| 3619 | static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags, BcParseNext next); | ||
| 3619 | 3620 | ||
| 3620 | static BcStatus bc_parse_operator(BcParse *p, BcLexType type, size_t start, | 3621 | static BcStatus bc_parse_operator(BcParse *p, BcLexType type, size_t start, |
| 3621 | size_t *nexprs, bool next) | 3622 | size_t *nexprs, bool next) |
| @@ -4027,7 +4028,7 @@ static BcStatus bc_parse_return(BcParse *p) | |||
| 4027 | bc_parse_push(p, BC_INST_RET0); | 4028 | bc_parse_push(p, BC_INST_RET0); |
| 4028 | else { | 4029 | else { |
| 4029 | 4030 | ||
| 4030 | s = bc_parse_expr(p, 0, bc_parse_next_expr); | 4031 | s = bc_parse_expr_empty_ok(p, 0, bc_parse_next_expr); |
| 4031 | if (s == BC_STATUS_PARSE_EMPTY_EXP) { | 4032 | if (s == BC_STATUS_PARSE_EMPTY_EXP) { |
| 4032 | bc_parse_push(p, BC_INST_RET0); | 4033 | bc_parse_push(p, BC_INST_RET0); |
| 4033 | s = bc_lex_next(&p->l); | 4034 | s = bc_lex_next(&p->l); |
| @@ -4690,7 +4691,7 @@ static BcStatus bc_parse_parse(BcParse *p) | |||
| 4690 | return s; | 4691 | return s; |
| 4691 | } | 4692 | } |
| 4692 | 4693 | ||
| 4693 | static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next) | 4694 | static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags, BcParseNext next) |
| 4694 | { | 4695 | { |
| 4695 | BcStatus s = BC_STATUS_SUCCESS; | 4696 | BcStatus s = BC_STATUS_SUCCESS; |
| 4696 | BcInst prev = BC_INST_PRINT; | 4697 | BcInst prev = BC_INST_PRINT; |
| @@ -4944,6 +4945,16 @@ static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next) | |||
| 4944 | return s; | 4945 | return s; |
| 4945 | } | 4946 | } |
| 4946 | 4947 | ||
| 4948 | static BcStatus bc_parse_expr(BcParse *p, uint8_t flags, BcParseNext next) | ||
| 4949 | { | ||
| 4950 | BcStatus s; | ||
| 4951 | |||
| 4952 | s = bc_parse_expr_empty_ok(p, flags, next); | ||
| 4953 | if (s == BC_STATUS_PARSE_EMPTY_EXP) | ||
| 4954 | return bc_error("empty expression"); | ||
| 4955 | return s; | ||
| 4956 | } | ||
| 4957 | |||
| 4947 | static void bc_parse_init(BcParse *p, size_t func) | 4958 | static void bc_parse_init(BcParse *p, size_t func) |
| 4948 | { | 4959 | { |
| 4949 | bc_parse_create(p, func, bc_parse_parse, bc_lex_token); | 4960 | bc_parse_create(p, func, bc_parse_parse, bc_lex_token); |
