From b4f33bbbb00a3e47e14081a9be352eb6a9b917b5 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 11 Apr 2019 22:47:18 +0000 Subject: [PATCH] llvm-undname: Fix crash on incomplete virtual this adjusts Found by oss-fuzz. Also remove an else-after-return, this part has no behavior change. llvm-svn: 358237 --- llvm/lib/Demangle/MicrosoftDemangle.cpp | 5 +++-- llvm/test/Demangle/invalid-manglings.test | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp index 194a152acb8f..f45df9413d7f 100644 --- a/llvm/lib/Demangle/MicrosoftDemangle.cpp +++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp @@ -481,7 +481,7 @@ Demangler::demangleFunctionIdentifierCode(StringView &MangledName) { if (MangledName.consumeFront("__")) return demangleFunctionIdentifierCode( MangledName, FunctionIdentifierCodeGroup::DoubleUnder); - else if (MangledName.consumeFront("_")) + if (MangledName.consumeFront("_")) return demangleFunctionIdentifierCode(MangledName, FunctionIdentifierCodeGroup::Under); return demangleFunctionIdentifierCode(MangledName, @@ -1575,7 +1575,8 @@ FuncClass Demangler::demangleFunctionClass(StringView &MangledName) { FuncClass VFlag = FC_VirtualThisAdjust; if (MangledName.consumeFront('R')) VFlag = FuncClass(VFlag | FC_VirtualThisAdjustEx); - + if (MangledName.empty()) + break; switch (MangledName.popFront()) { case '0': return FuncClass(FC_Private | FC_Virtual | VFlag); diff --git a/llvm/test/Demangle/invalid-manglings.test b/llvm/test/Demangle/invalid-manglings.test index 5d6f3160a95d..4c155b765a43 100644 --- a/llvm/test/Demangle/invalid-manglings.test +++ b/llvm/test/Demangle/invalid-manglings.test @@ -99,3 +99,8 @@ ; CHECK-EMPTY: ; CHECK-NEXT: ?B@?$?K$H? ; CHECK-NEXT: error: Invalid mangled name + +??C@$ +; CHECK-EMPTY: +; CHECK-NEXT: ??C@$ +; CHECK-NEXT: error: Invalid mangled name