From a5cbacf92b1c49461fd2ebca74374a4538a8c415 Mon Sep 17 00:00:00 2001 From: Eyal Itkin Date: Sun, 24 Nov 2024 12:57:48 +0200 Subject: [PATCH] Rewriter: Handle unknown write targets Add error checks for cases in which the write target is unknown and ensure all error cases indeed abort the execution to avoid internal crash. Resolves #13502. Signed-off-by: Eyal Itkin --- mesonbuild/rewriter.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mesonbuild/rewriter.py b/mesonbuild/rewriter.py index 919bd3847b13..49e333384ccd 100644 --- a/mesonbuild/rewriter.py +++ b/mesonbuild/rewriter.py @@ -517,16 +517,21 @@ def process_kwargs(self, cmd): arg_node = node.args elif cmd['function'] == 'target': tmp = self.find_target(cmd['id']) - if tmp: - node = tmp['node'] - arg_node = node.args + if not tmp: + mlog.error('Unable to find the target', mlog.bold(cmd['id']), *self.on_error()) + return self.handle_error() + node = tmp['node'] + arg_node = node.args elif cmd['function'] == 'dependency': tmp = self.find_dependency(cmd['id']) - if tmp: - node = tmp['node'] - arg_node = node.args + if not tmp: + mlog.error('Unable to find the dependency', mlog.bold(cmd['id']), *self.on_error()) + return self.handle_error() + node = tmp['node'] + arg_node = node.args if not node: - mlog.error('Unable to find the function node') + mlog.error('Unable to find the function node', *self.on_error()) + return self.handle_error() assert isinstance(node, FunctionNode) assert isinstance(arg_node, ArgumentNode) # Transform the key nodes to plain strings