From 9dcbf460ff692c049e4d327afcbdbc39ba4e8c65 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 3 Sep 2025 19:08:05 +0200 Subject: Validate that memory access is done via variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The address sanitizer is now able to detect whenever in an instruction a memory access is done without using variables. This is now detected for all instructions except for branching, which falls outside of this scope. Moreover, simple arithmetics is allowed and bounds are checked for simple cases. That being said, more involved bound checks should be done with other tools (e.g. emulators). Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/node.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib/xixanta/src/node.rs') diff --git a/lib/xixanta/src/node.rs b/lib/xixanta/src/node.rs index 7cfc107..465dde2 100644 --- a/lib/xixanta/src/node.rs +++ b/lib/xixanta/src/node.rs @@ -1,5 +1,13 @@ use std::fmt; +/// Returns true if this String follows the naming +/// conventions as expected by the address sanitizer. +pub fn is_asan_friendly_name(string: &str) -> bool { + let name = string.split("::").last().unwrap_or(""); + + name.starts_with("zp_") || name.starts_with("wr_") || name.starts_with("m_") +} + /// A Positioned String. That is, a String which also has information on the /// line number and the column range. #[derive(Debug, Default, Clone, PartialEq)] @@ -456,3 +464,25 @@ impl PNode { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn is_asan_friendly_name_test() { + let tests = vec![ + ("zp_name", true), + ("name", false), + ("Scope::zp_name", true), + ("Scope::Inner::zp_good", true), + ("Scope::Inner::bad", false), + ]; + + for (name, expect) in tests { + let string = String::from(name); + + assert_eq!(is_asan_friendly_name(&string), expect); + } + } +} -- cgit v1.2.3