summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2018-04-23 10:53:18 +0200
committerDenys Vlasenko2018-04-23 10:53:18 +0200
commit2454e678cb7d241097ee9ce4b2114a136f1b57ec (patch)
treee5a3a5667962c73f43ee8024a2a9152fd45b9577
parentc21dfaf836cf0eb5317035bc20395c751a205934 (diff)
downloadbusybox-2454e678cb7d241097ee9ce4b2114a136f1b57ec.zip
busybox-2454e678cb7d241097ee9ce4b2114a136f1b57ec.tar.gz
awk: do not allow $(-1)
function old new delta EMSG_NEGATIVE_FIELD - 25 +25 evaluate 3390 3403 +13 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 38/0) Total: 38 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/awk.c3
-rwxr-xr-xtestsuite/awk.tests6
2 files changed, 9 insertions, 0 deletions
diff --git a/editors/awk.c b/editors/awk.c
index d54249b..bafc9ba 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -598,6 +598,7 @@ static const char EMSG_NOT_ARRAY[] ALIGN1 = "Not an array";
static const char EMSG_POSSIBLE_ERROR[] ALIGN1 = "Possible syntax error";
static const char EMSG_UNDEF_FUNC[] ALIGN1 = "Call to undefined function";
static const char EMSG_NO_MATH[] ALIGN1 = "Math support is not compiled in";
+static const char EMSG_NEGATIVE_FIELD[] ALIGN1 = "Access to negative field";
static void zero_out_var(var *vp)
{
@@ -2949,6 +2950,8 @@ static var *evaluate(node *op, var *res)
case XC( OC_FIELD ): {
int i = (int)getvar_i(R.v);
+ if (i < 0)
+ syntax_error(EMSG_NEGATIVE_FIELD);
if (i == 0) {
res = intvar[F0];
} else {
diff --git a/testsuite/awk.tests b/testsuite/awk.tests
index ad0583a..3933fef 100755
--- a/testsuite/awk.tests
+++ b/testsuite/awk.tests
@@ -339,5 +339,11 @@ testing "awk handles invalid for loop" \
"awk '{ for() }' 2>&1" "awk: cmd. line:1: Unexpected token\n" "" ""
# testing "description" "command" "result" "infile" "stdin"
+testing 'awk negative field access' \
+ 'awk 2>&1 -- '\''{ $(-1) }'\' \
+ "awk: cmd. line:1: Access to negative field\n" \
+ '' \
+ 'anything'
+
exit $FAILCOUNT