[llvm] r358835 - llvm-undname: Improve string literal demangling with embedded \0 chars

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 20 16:59:06 PDT 2019


Author: nico
Date: Sat Apr 20 16:59:06 2019
New Revision: 358835

URL: http://llvm.org/viewvc/llvm-project?rev=358835&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Demangle/MicrosoftDemangle.cpp
    llvm/trunk/test/Demangle/ms-string-literals.test

Modified: llvm/trunk/lib/Demangle/MicrosoftDemangle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Demangle/MicrosoftDemangle.cpp?rev=358835&r1=358834&r2=358835&view=diff
==============================================================================
--- llvm/trunk/lib/Demangle/MicrosoftDemangle.cpp (original)
+++ llvm/trunk/lib/Demangle/MicrosoftDemangle.cpp Sat Apr 20 16:59:06 2019
@@ -1088,6 +1088,9 @@ static void outputHex(OutputStream &OS,
 
 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
   // 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
   // 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;

Modified: llvm/trunk/test/Demangle/ms-string-literals.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Demangle/ms-string-literals.test?rev=358835&r1=358834&r2=358835&view=diff
==============================================================================
--- llvm/trunk/test/Demangle/ms-string-literals.test (original)
+++ llvm/trunk/test/Demangle/ms-string-literals.test Sat Apr 20 16:59:06 2019
@@ -771,3 +771,13 @@
 
 ??_C at _0CG@HJGBPLNO at l?$AAo?$AAo?$AAk?$AAA?$AAh?$AAe?$AAa?$AAd?$AAH?$AAa?$AAr?$AAd?$AAB?$AAr?$AAe?$AA@
 ; CHECK: u"lookAheadHardBre"...
+
+
+; These are u16 strings that the diagnostic would classify as u32 -- except
+; that their byte length % 4 is 2, so they can't be u32.
+
+??_C at _05LABPAAN@b?$AA?$AA?$AA?$AA?$AA@
+; CHECK: u"b\0"
+
+??_C at _0CC@MBPKDIAM at a?$AA?$AA?$AAb?$AA?$AA?$AAc?$AA?$AA?$AAd?$AA?$AA?$AAe?$AA?$AA?$AAf?$AA?$AA?$AAg?$AA?$AA?$AAh?$AA?$AA?$AA@
+; CHECK: u"a\0b\0c\0d\0e\0f\0g\0h\0"...




More information about the llvm-commits mailing list