Skip to content

Commit ba97e80

Browse files
committed
[sanitizer] Fail __sanitizer_symbolize_demangle instead of returning input
LLVMSymbolizer::DemangleName returns the same input if it can't demangle. We can't tell if this is already demangled or format is unsupported. Internally DemangleName uses nonMicrosoftDemangle which can report a failure.
1 parent 7b3bdc1 commit ba97e80

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

compiler-rt/lib/sanitizer_common/symbolizer/sanitizer_symbolize.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "llvm/DebugInfo/Symbolize/DIPrinter.h"
1919
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
20+
#include "llvm/Demangle/Demangle.h"
2021

2122
static llvm::symbolize::LLVMSymbolizer *Symbolizer = nullptr;
2223
static bool Demangle = true;
@@ -117,8 +118,9 @@ void __sanitizer_symbolize_flush() {
117118

118119
bool __sanitizer_symbolize_demangle(const char *Name, char *Buffer,
119120
int MaxLength) {
120-
std::string Result =
121-
llvm::symbolize::LLVMSymbolizer::DemangleName(Name, nullptr);
121+
std::string Result;
122+
if (!llvm::nonMicrosoftDemangle(Name, Result))
123+
return false;
122124
return __sanitizer::internal_snprintf(Buffer, MaxLength, "%s",
123125
Result.c_str()) < MaxLength;
124126
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %clangxx -O0 %s -o %t && %run %t
2+
3+
// REQUIRES: internal_symbolizer
4+
5+
// FIXME: link internal_symbolizer.
6+
// XFAIL: asan, hwasan, ubsan
7+
8+
#include <algorithm>
9+
#include <assert.h>
10+
#include <string.h>
11+
12+
extern "C" bool __sanitizer_symbolize_demangle(const char *Name, char *Buffer,
13+
int MaxLength);
14+
15+
int main() {
16+
char out[128];
17+
assert(!__sanitizer_symbolize_demangle("1A", out, sizeof(out)));
18+
19+
const char name[] = "_Z3fooi";
20+
for (int i = 1; i < sizeof(out); ++i) {
21+
memset(out, 1, sizeof(out));
22+
assert(__sanitizer_symbolize_demangle(name, out, i) == (i > 8));
23+
assert(i < 9 || 0 == strncmp(out, "foo(int)", i - 1));
24+
}
25+
}

compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// RUN: %clangxx -frtti -fsanitize=null,vptr -fno-sanitize-recover=vptr -g %s -O3 -o %t
22
// RUN: not %run %t 2>&1 | FileCheck %s
33

4-
// FIXME: Investigate.
5-
// XFAIL: internal_symbolizer && (ubsan-tsan || ubsan-msan)
6-
74
// REQUIRES: shared_cxxabi
85
// REQUIRES: cxxabi
96
// UNSUPPORTED: target={{.*windows-msvc.*}}

compiler-rt/test/ubsan/TestCases/TypeCheck/vptr.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
// RUN: echo "vptr_check:S" > %t.loc-supp
3737
// RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.loc-supp"' not %run %t x- 2>&1 | FileCheck %s --check-prefix=CHECK-LOC-SUPPRESS
3838

39-
// FIXME: Investigate.
40-
// XFAIL: internal_symbolizer && (ubsan-tsan || ubsan-msan)
41-
4239
// REQUIRES: stable-runtime, cxxabi
4340
// UNSUPPORTED: target={{.*windows-msvc.*}}
4441
// Suppressions file not pushed to the device.

0 commit comments

Comments
 (0)