From 87874a62d1e1ae43b7b57ae19f48d666f37784da Mon Sep 17 00:00:00 2001 From: Christian Kreibich Date: Wed, 13 Sep 2023 23:01:56 -0700 Subject: [PATCH] Avoid assertion/tag error on invalid table constructor index expression If an index expression in a table constructor isn't a list, don't abort with an assertion failure (on debug builds) or a bad tag check. Instead, mark the constructor expression erroneous and return gracefully. The following... global a_table: table[subnet] of string = { 1.2.3.4/24 = "unspecified", # should have been [1.2.3.4/24] = "unspecified", }; ...now yields: $ zeek ./test.zeek error in ././test.zeek, line 2: table constructor index is not a list (1.2.3.0/24 = unspecified) error in ././test.zeek, line 2: type clash in assignment (a_table = table(1.2.3.0/24 = unspecified)) --- src/Expr.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Expr.cc b/src/Expr.cc index c741e65938..d2d0cbf118 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -3605,8 +3605,14 @@ TableConstructorExpr::TableConstructorExpr(ListExprPtr constructor_list, auto val_expr = expr->AsAssignExpr()->GetOp2(); auto yield_type = GetType()->AsTableType()->Yield(); + if ( idx_expr->Tag() != EXPR_LIST ) + { + expr->Error("table constructor index is not a list"); + SetError(); + return; + } + // Promote LHS - assert(idx_expr->Tag() == EXPR_LIST); ExprPList& idx_exprs = idx_expr->AsListExpr()->Exprs(); if ( idx_exprs.length() != static_cast(indices.size()) )