summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Demangle
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2019-04-20 23:59:06 +0000
committerNico Weber <nicolasweber@gmx.de>2019-04-20 23:59:06 +0000
commit8eeaf5178dfda82b51766ea106febd7f563bc08f (patch)
tree0dae3af91f1a7c07f2cc6bf05cd6aeffbe1ced72 /llvm/lib/Demangle
parentf2654b638d534ae6025dfe87484c0b5bdde4c6f8 (diff)
downloadbcm5719-llvm-8eeaf5178dfda82b51766ea106febd7f563bc08f.tar.gz
bcm5719-llvm-8eeaf5178dfda82b51766ea106febd7f563bc08f.zip
llvm-undname: Improve string literal demangling with embedded \0 chars
- Don't assert when a string looks like a u32 string to the heuristic but doesn't have a length that's 0 mod 4. Instead, classify those as u16 with embedded \0 chars. Found by oss-fuzz. - Print embedded nul bytes as \0 instead of \x00. llvm-svn: 358835
Diffstat (limited to 'llvm/lib/Demangle')
-rw-r--r--llvm/lib/Demangle/MicrosoftDemangle.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp
index ebe2ef5de09..6431e4ab130 100644
--- a/llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1088,6 +1088,9 @@ static void outputHex(OutputStream &OS, unsigned C) {
static void outputEscapedChar(OutputStream &OS, unsigned C) {
switch (C) {
+ case '\0': // nul
+ OS << "\\0";
+ return;
case '\'': // single quote
OS << "\\\'";
return;
@@ -1165,7 +1168,7 @@ static unsigned guessCharByteSize(const uint8_t *StringBytes, unsigned NumChars,
// 2-byte, or 4-byte null terminator.
if (NumBytes < 32) {
unsigned TrailingNulls = countTrailingNullBytes(StringBytes, NumChars);
- if (TrailingNulls >= 4)
+ if (TrailingNulls >= 4 && NumBytes % 4 == 0)
return 4;
if (TrailingNulls >= 2)
return 2;
@@ -1179,7 +1182,7 @@ static unsigned guessCharByteSize(const uint8_t *StringBytes, unsigned NumChars,
// perfect and is biased towards languages that have ascii alphabets, but this
// was always going to be best effort since the encoding is lossy.
unsigned Nulls = countEmbeddedNulls(StringBytes, NumChars);
- if (Nulls >= 2 * NumChars / 3)
+ if (Nulls >= 2 * NumChars / 3 && NumBytes % 4 == 0)
return 4;
if (Nulls >= NumChars / 3)
return 2;
OpenPOWER on IntegriCloud