llvm.org GIT mirror llvm / 594fc0d
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358835 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Weber 1 year, 7 months ago
2 changed file(s) with 15 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
10871087
10881088 static void outputEscapedChar(OutputStream &OS, unsigned C) {
10891089 switch (C) {
1090 case '\0': // nul
1091 OS << "\\0";
1092 return;
10901093 case '\'': // single quote
10911094 OS << "\\\'";
10921095 return;
11641167 // 2-byte, or 4-byte null terminator.
11651168 if (NumBytes < 32) {
11661169 unsigned TrailingNulls = countTrailingNullBytes(StringBytes, NumChars);
1167 if (TrailingNulls >= 4)
1170 if (TrailingNulls >= 4 && NumBytes % 4 == 0)
11681171 return 4;
11691172 if (TrailingNulls >= 2)
11701173 return 2;
11781181 // perfect and is biased towards languages that have ascii alphabets, but this
11791182 // was always going to be best effort since the encoding is lossy.
11801183 unsigned Nulls = countEmbeddedNulls(StringBytes, NumChars);
1181 if (Nulls >= 2 * NumChars / 3)
1184 if (Nulls >= 2 * NumChars / 3 && NumBytes % 4 == 0)
11821185 return 4;
11831186 if (Nulls >= NumChars / 3)
11841187 return 2;
770770
771771 ??_C@_0CG@HJGBPLNO@l?$AAo?$AAo?$AAk?$AAA?$AAh?$AAe?$AAa?$AAd?$AAH?$AAa?$AAr?$AAd?$AAB?$AAr?$AAe?$AA@
772772 ; CHECK: u"lookAheadHardBre"...
773
774
775 ; These are u16 strings that the diagnostic would classify as u32 -- except
776 ; that their byte length % 4 is 2, so they can't be u32.
777
778 ??_C@_05LABPAAN@b?$AA?$AA?$AA?$AA?$AA@
779 ; CHECK: u"b\0"
780
781 ??_C@_0CC@MBPKDIAM@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@
782 ; CHECK: u"a\0b\0c\0d\0e\0f\0g\0h\0"...