summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2025-03-31 14:27:47 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2025-07-29 02:38:27 +0200
commit212718fc9127193b98da904a5debae6e4fd7dfc2 (patch)
tree16e9ce51597c897e57190c1e8697d5ad0c8a0742
parent18591a8d7fb769041da57fefb7e335b7ac5a8afa (diff)
json: fix error propagation when parsing binop lhs/rhs
commit 1b6470ab1c4eff46986e65db1b69278f13c26666 upstream. Malformed input returns NULL when decoding left/right side of binop. This causes a NULL dereference in expr_evaluate_binop; left/right must point to a valid expression. Fix this in the parser, else would have to sprinkle NULL checks all over the evaluation code. After fix, loading the bogon yields: internal:0:0-0: Error: Malformed object (too many properties): '{}'. internal:0:0-0: Error: could not decode binop rhs, '<<'. internal:0:0-0: Error: Invalid mangle statement value internal:0:0-0: Error: Parsing expr array at index 1 failed. internal:0:0-0: Error: Parsing command array at index 3 failed. Fixes: 0ac39384fd9e ("json: Accept more than two operands in binary expressions") Signed-off-by: Florian Westphal <fw@strlen.de> Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/parser_json.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/parser_json.c b/src/parser_json.c
index e8fed0d2..c7649ccf 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1138,11 +1138,25 @@ static struct expr *json_parse_binop_expr(struct json_ctx *ctx,
if (json_array_size(root) > 2) {
left = json_parse_primary_expr(ctx, json_array_get(root, 0));
+ if (!left) {
+ json_error(ctx, "Failed to parse LHS of binop expression.");
+ return NULL;
+ }
right = json_parse_primary_expr(ctx, json_array_get(root, 1));
+ if (!right) {
+ json_error(ctx, "Failed to parse RHS of binop expression.");
+ expr_free(left);
+ return NULL;
+ }
left = binop_expr_alloc(int_loc, thisop, left, right);
for (i = 2; i < json_array_size(root); i++) {
jright = json_array_get(root, i);
right = json_parse_primary_expr(ctx, jright);
+ if (!right) {
+ json_error(ctx, "Failed to parse RHS of binop expression.");
+ expr_free(left);
+ return NULL;
+ }
left = binop_expr_alloc(int_loc, thisop, left, right);
}
return left;