Skip to content

Commit 0faf10b

Browse files
authored
Fix asan stacktrace entry parsing (#160)
1 parent 26f7c3d commit 0faf10b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

libcasr/src/asan.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ impl ParseStacktrace for AsanStacktrace {
5959
// (module+0xdeadbeef)
6060
// TODO: (module)
6161
// We have to distinguish from (anonymous namespace) and function arguments.
62-
// TODO: module path may contain (.
63-
// We forbid ( in module path to distinguish from function arguments.
64-
// However, we allow ( when there is no function.
62+
// TODO: module path may contain ( and ).
63+
// We forbid ( and ) in module path to distinguish from function arguments.
64+
// However, we allow ( and ) when there is no function.
6565
// Regex::captures returns leftmost-first match, so, it won't match (BuildId: ).
6666
let re = if has_function {
67-
Regex::new(r"\(([^(]+)\+0x([0-9a-f]+)\)").unwrap()
67+
Regex::new(r"\(([^()]+)\+0x([0-9a-f]+)\)").unwrap()
6868
} else {
6969
Regex::new(r"\((.+)\+0x([0-9a-f]+)\)").unwrap()
7070
};
@@ -85,6 +85,11 @@ impl ParseStacktrace for AsanStacktrace {
8585
// in function[(args)] [const] path
8686
// TODO: source file path may contain )
8787
if has_function {
88+
if location.len() < 3 {
89+
return Err(Error::Casr(format!(
90+
"Couldn't parse stack trace entry: {entry}"
91+
)));
92+
}
8893
location = location[3..].trim();
8994
// in typeinfo name for xlnt::detail::compound_document_istreambuf
9095
// TODO: there may be no function and source path may start with for and space.
@@ -250,6 +255,7 @@ mod tests {
250255
"#11 0xe086ff in xml::serializer::handle_error(genxStatus) const /xlnt/third-party/libstudxml/libstudxml/serializer.cxx:116:7",
251256
" #7 0xa180bf in typeinfo name for xlnt::detail::compound_document_istreambuf (/load_afl+0xa180bf)",
252257
" #9 0xb98663 in xlnt::detail::number_serialiser::deserialise(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, long*) const (/casr_tests/bin/load_fuzzer+0xb98663)",
258+
"#4 0x998b40 in (anonymous namespace)::decrypt_xl<unsigned char> > const&) /xlnt/er+0x426cbd)", // invalid
253259
];
254260

255261
let trace = raw_stacktrace
@@ -411,5 +417,13 @@ mod tests {
411417
"/casr_tests/bin/load_fuzzer".to_string()
412418
);
413419
assert_eq!(stacktrace[19].offset, 0xb98663);
420+
421+
assert_eq!(stacktrace[20].address, 0x998b40);
422+
assert_eq!(
423+
stacktrace[20].function,
424+
// invalid result in invalid frame
425+
"(anonymous namespace)::decrypt_xl<unsigned char> > const&) /xlnt/er+0x426cbd)"
426+
.to_string()
427+
);
414428
}
415429
}

0 commit comments

Comments
 (0)