← Commit list

dac15a10a

Brian Foley
Brian Foley
2019-01-21
SUCCESS Duration: 152s

Subject

awk: Guard pointer chasing when parsing ternary expressions.

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

editors/awk.c+2 -1
@@ -1265,7 +1265,7 @@ static node *parse_expr(uint32_t iexp)
debug_printf_parse("%s(%x)\n", __func__, iexp);
sn.info = PRIMASK;
- sn.r.n = glptr = NULL;
+ sn.r.n = sn.a.n = glptr = NULL;
xtc = TC_OPERAND | TC_UOPPRE | TC_REGEXP | iexp;
while (!((tc = next_token(xtc)) & iexp)) {
@@ -1287,6 +1287,7 @@ static node *parse_expr(uint32_t iexp)
|| ((t_info == vn->info) && ((t_info & OPCLSMASK) == OC_COLON))
) {
vn = vn->a.n;
+ if (!vn->a.n) syntax_error(EMSG_UNEXP_TOKEN);
}
if ((t_info & OPCLSMASK) == OC_TERNARY)
t_info += P(6);
testsuite/awk.tests+3 -0
@@ -338,6 +338,9 @@ testing "awk continue" \
testing "awk handles invalid for loop" \
"awk '{ for() }' 2>&1" "awk: cmd. line:1: Unexpected token\n" "" ""
+testing "awk handles colon not preceded by ternary" \
+ "awk 'foo:bar:' 2>&1" "awk: cmd. line:1: Unexpected token\n" "" ""
+
# testing "description" "command" "result" "infile" "stdin"
testing 'awk negative field access' \
'awk 2>&1 -- '\''{ $(-1) }'\' \