awk: disallow "str"++, closes bug 12981
authorDenys Vlasenko <vda.linux@googlemail.com>
Mon, 8 Jun 2020 23:33:54 +0000 (01:33 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Mon, 8 Jun 2020 23:33:54 +0000 (01:33 +0200)
function                                             old     new   delta
parse_expr                                           887     896      +9

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
editors/awk.c
testsuite/awk.tests

index 70df2fdb44f5ffadf09a6729f64f425ae86d6f3d..f7451ae32264e4fe414d4e09050a1e6873330984 100644 (file)
@@ -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:
index b5008290fe568ce02320769c501e0beec4914c7e..87f6b50079f8763b721c9c1a711bc24f201b1c0a 100755 (executable)
@@ -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