]> granicus.if.org Git - llvm/commitdiff
llvm-undname: Fix an assert-on-invalid
authorNico Weber <nicolasweber@gmx.de>
Wed, 3 Apr 2019 23:19:39 +0000 (23:19 +0000)
committerNico Weber <nicolasweber@gmx.de>
Wed, 3 Apr 2019 23:19:39 +0000 (23:19 +0000)
Found by oss-fuzz, fixes issues 12428 and 12429 on oss-fuzz.

Differential Revision: https://reviews.llvm.org/D60204

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357647 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Demangle/MicrosoftDemangle.cpp
test/Demangle/invalid-manglings.test

index b8e39c415270776079089b5e7a4153efbdb5ee06..b4e5cef7ac527b52ca4f8bd72d0424b09b7fc9f2 100644 (file)
@@ -466,6 +466,10 @@ IdentifierNode *
 Demangler::demangleFunctionIdentifierCode(StringView &MangledName) {
   assert(MangledName.startsWith('?'));
   MangledName = MangledName.dropFront();
+  if (MangledName.empty()) {
+    Error = true;
+    return nullptr;
+  }
 
   if (MangledName.consumeFront("__"))
     return demangleFunctionIdentifierCode(
@@ -637,6 +641,7 @@ translateIntrinsicFunctionCode(char CH, FunctionIdentifierCodeGroup Group) {
 IdentifierNode *
 Demangler::demangleFunctionIdentifierCode(StringView &MangledName,
                                           FunctionIdentifierCodeGroup Group) {
+  assert(!MangledName.empty());
   switch (Group) {
   case FunctionIdentifierCodeGroup::Basic:
     switch (char CH = MangledName.popFront()) {
index 6883a46d8d3b6282e3edf1d60267630e17b915f4..af919282bb825d4c695057300d7424dd77371f3b 100644 (file)
@@ -14,3 +14,8 @@
 ; CHECK-EMPTY:
 ; CHECK-NEXT: ?@@8
 ; CHECK-NEXT: error: Invalid mangled name
+
+??
+; CHECK-EMPTY:
+; CHECK-NEXT: ??
+; CHECK-NEXT: error: Invalid mangled name