aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-06-09 01:33:54 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2020-06-09 01:33:54 +0200
commit6f7a0096496a5a9e90638dc01e947015cc776110 (patch)
tree9c069ee55413ec7acef2d1e152859b0f14c9b11f
parent45fa3f18adf57ef9d743038743d9c90573aeeb91 (diff)
downloadbusybox-w32-6f7a0096496a5a9e90638dc01e947015cc776110.tar.gz
busybox-w32-6f7a0096496a5a9e90638dc01e947015cc776110.tar.bz2
busybox-w32-6f7a0096496a5a9e90638dc01e947015cc776110.zip
awk: disallow "str"++, closes bug 12981
function old new delta parse_expr 887 896 +9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/awk.c4
-rwxr-xr-xtestsuite/awk.tests8
2 files changed, 11 insertions, 1 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 70df2fdb4..f7451ae32 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -1359,8 +1359,10 @@ static node *parse_expr(uint32_t iexp)
1359 v = cn->l.v = xzalloc(sizeof(var)); 1359 v = cn->l.v = xzalloc(sizeof(var));
1360 if (tc & TC_NUMBER) 1360 if (tc & TC_NUMBER)
1361 setvar_i(v, t_double); 1361 setvar_i(v, t_double);
1362 else 1362 else {
1363 setvar_s(v, t_string); 1363 setvar_s(v, t_string);
1364 xtc &= ~TC_UOPPOST; /* "str"++ is not allowed */
1365 }
1364 break; 1366 break;
1365 1367
1366 case TC_REGEXP: 1368 case TC_REGEXP:
diff --git a/testsuite/awk.tests b/testsuite/awk.tests
index b5008290f..87f6b5007 100755
--- a/testsuite/awk.tests
+++ b/testsuite/awk.tests
@@ -390,5 +390,13 @@ testing 'awk negative field access' \
390 '' \ 390 '' \
391 'anything' 391 'anything'
392 392
393# was misinterpreted as (("str"++) i) instead of ("str" (++i))
394# (and was executed: "str"++ is "0", thus concatenating "0" and "1"):
395testing 'awk do not allow "str"++' \
396 'awk -v i=1 "BEGIN {print \"str\" ++i}"' \
397 "str2\n" \
398 '' \
399 'anything'
400
393 401
394exit $FAILCOUNT 402exit $FAILCOUNT