[git commit] awk: disallow "str"++, closes bug 12981

Denys Vlasenko vda.linux at googlemail.com
Mon Jun 8 23:33:54 UTC 2020


commit: https://git.busybox.net/busybox/commit/?id=6f7a0096496a5a9e90638dc01e947015cc776110
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
parse_expr                                           887     896      +9

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 editors/awk.c       | 4 +++-
 testsuite/awk.tests | 8 ++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

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)
 					v = cn->l.v = xzalloc(sizeof(var));
 					if (tc & TC_NUMBER)
 						setvar_i(v, t_double);
-					else
+					else {
 						setvar_s(v, t_string);
+						xtc &= ~TC_UOPPOST; /* "str"++ is not allowed */
+					}
 					break;
 
 				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' \
 	'' \
 	'anything'
 
+# was misinterpreted as (("str"++) i) instead of ("str" (++i))
+# (and was executed: "str"++ is "0", thus concatenating "0" and "1"):
+testing 'awk do not allow "str"++' \
+	'awk -v i=1 "BEGIN {print \"str\" ++i}"' \
+	"str2\n" \
+	'' \
+	'anything'
+
 
 exit $FAILCOUNT


More information about the busybox-cvs mailing list