From d64ed8c531b03a75d4e20d48f5d5f662898e60f7 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 15 Dec 2025 11:54:36 +0100 Subject: Do not allow empty strings on .include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/parser.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs index 7a892b0..e227ade 100644 --- a/lib/xixanta/src/parser.rs +++ b/lib/xixanta/src/parser.rs @@ -923,6 +923,15 @@ impl Parser { // working directory. This way we construct the absolute path for the // given file. let file_path = self.fetch_path_from(node.args.as_ref().unwrap().first().unwrap())?; + if file_path.is_empty() { + return Err(Error { + line: node.value.line, + global: false, + source: self.sources.get(self.current_source).unwrap().clone(), + message: ".include statement with an empty string".to_string(), + } + .into()); + } let Some(current_source) = self.sources.get(self.current_source) else { panic!("mismatch between the number of sources and the current one"); }; @@ -2074,6 +2083,21 @@ mod tests { ); } + #[test] + fn error_on_empty_include_string() { + let mut parser = Parser::default(); + let line = ".include \" \""; + + let err = parser + .parse(line.as_bytes(), &SourceInfo::default()) + .unwrap_err(); + + assert_eq!( + err.first().unwrap().message, + ".include statement with an empty string" + ); + } + // Regular instructions. #[test] -- cgit v1.2.3