From ec0831e82851862a6af2ade12a996634d5dfc64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= Date: Thu, 9 Jan 2025 22:29:14 +0100 Subject: [PATCH] Prevent assignments on relative references MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is a really weird thing to do, but on a twisted way I can see how someone could think of such a monstrosity. Panicking on such a case is not valid because that's not the fault from the assembler but from the programmer, and so a proper message should be displayed instead. This was detected via the fuzzer, but it was a side effect from e7c5e63d04f6 ("Evaluate bare numbers as decimal values"). Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/assembler.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index c59150c..1f7c9a5 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -929,6 +929,7 @@ impl<'a> Assembler<'a> { Ok(right) } + // Evaluate the given node as a relative reference. fn evaluate_anonymous_relative_reference(&mut self, node: &PNode) -> Result { self.literal_mode = Some(LiteralMode::Plain); @@ -957,7 +958,12 @@ impl<'a> Assembler<'a> { }), } } - _ => panic!("unexpected evaluation of relative reference"), + Stage::Context => Err(Error { + line: node.value.line, + source: self.source_for(node), + global: false, + message: "trying to evaluate a relative reference as a bare value".to_string(), + }), } } @@ -2263,6 +2269,16 @@ mod tests { ); } + #[test] + fn trying_to_assign_on_relative_reference() { + assert_error( + "Var = :-", + 1, + false, + "trying to evaluate a relative reference as a bare value", + ); + } + #[test] fn unknown_variables() { assert_error(