From d746ea5234e7b5f56b11bb820498dec53b9cee32 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 12 May 2025 15:53:06 +0100 Subject: [PATCH] lang: ast: fix nullptr deref in expr_finalise_arith when calculating ast node bounds --- lang/ast/expr/arith.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lang/ast/expr/arith.c b/lang/ast/expr/arith.c index c3c1ded..fe49816 100644 --- a/lang/ast/expr/arith.c +++ b/lang/ast/expr/arith.c @@ -379,18 +379,28 @@ enum ivy_status expr_finalise_arith( op = op_node->n_op; tmp = b_queue_pop_back(&q); op_node->n_right = b_unbox(struct ivy_ast_node, tmp, n_entry); - op_node->n_right->n_parent = (struct ivy_ast_node *)op_node; - ivy_ast_node_extend_bounds_recursive( - (struct ivy_ast_node *)op_node, (struct ivy_ast_node *)tmp); + + if (op_node->n_right) { + op_node->n_right->n_parent = (struct ivy_ast_node *)op_node; + + ivy_ast_node_extend_bounds_recursive( + (struct ivy_ast_node *)op_node, + (struct ivy_ast_node *)tmp); + } if (op->op_arity == IVY_OP_BINARY) { tmp = b_queue_pop_back(&q); op_node->n_left = b_unbox(struct ivy_ast_node, tmp, n_entry); - op_node->n_left->n_parent = (struct ivy_ast_node *)op_node; - ivy_ast_node_extend_bounds_recursive( - (struct ivy_ast_node *)op_node, - (struct ivy_ast_node *)tmp); + + if (op_node->n_left) { + op_node->n_left->n_parent + = (struct ivy_ast_node *)op_node; + + ivy_ast_node_extend_bounds_recursive( + (struct ivy_ast_node *)op_node, + (struct ivy_ast_node *)tmp); + } } /* ...and push the newly-completed operator node to the operand