llvm-undname: Fix stack overflow on invalid found by oss-fuzz

llvm-svn: 358852
This commit is contained in:
Nico Weber 2019-04-21 14:25:07 +00:00
parent f985e31254
commit aa162682ca
2 changed files with 6 additions and 1 deletions

View File

@ -1292,7 +1292,7 @@ Demangler::demangleStringLiteral(StringView &MangledName) {
unsigned BytesDecoded = 0;
while (!MangledName.consumeFront('@')) {
if (MangledName.size() < 1)
if (MangledName.size() < 1 || BytesDecoded >= MaxStringByteLength)
goto StringLiteralError;
StringBytes[BytesDecoded++] = demangleCharLiteral(MangledName);
}

View File

@ -159,3 +159,8 @@
; CHECK-EMPTY:
; CHECK-NEXT: ??_C@_1301234567@a
; CHECK-NEXT: error: Invalid mangled name
??_C@_0601234567@abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRTSUVWXYZabcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRTSUVWXYZabcdefghijklmnopqrtsuvwxyz
; CHECK-EMPTY:
; CHECK-NEXT: ??_C@_0601234567@abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRTSUVWXYZabcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRTSUVWXYZabcdefghijklmnopqrtsuvwxyz
; CHECK-NEXT: error: Invalid mangled name