Skip to content

Commit 03db625

Browse files
committedApr 11, 2019
llvm-undname: Fix out-of-bounds read on invalid intrinsic function code
Found by inspection. llvm-svn: 358239
1 parent e5b6265 commit 03db625

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed
 

‎llvm/include/llvm/Demangle/MicrosoftDemangle.h

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ class Demangler {
207207
NamedIdentifierNode *demangleBackRefName(StringView &MangledName);
208208
IdentifierNode *demangleTemplateInstantiationName(StringView &MangledName,
209209
NameBackrefBehavior NBB);
210+
IntrinsicFunctionKind
211+
translateIntrinsicFunctionCode(char CH, FunctionIdentifierCodeGroup Group);
210212
IdentifierNode *demangleFunctionIdentifierCode(StringView &MangledName);
211213
IdentifierNode *
212214
demangleFunctionIdentifierCode(StringView &MangledName,

‎llvm/lib/Demangle/MicrosoftDemangle.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,18 @@ Demangler::demangleLiteralOperatorIdentifier(StringView &MangledName) {
511511
return N;
512512
}
513513

514-
static IntrinsicFunctionKind
515-
translateIntrinsicFunctionCode(char CH, FunctionIdentifierCodeGroup Group) {
514+
IntrinsicFunctionKind
515+
Demangler::translateIntrinsicFunctionCode(char CH,
516+
FunctionIdentifierCodeGroup Group) {
517+
using IFK = IntrinsicFunctionKind;
518+
if (!(CH >= '0' && CH <= '9') && !(CH >= 'A' && CH <= 'Z')) {
519+
Error = true;
520+
return IFK::None;
521+
}
522+
516523
// Not all ? identifiers are intrinsics *functions*. This function only maps
517524
// operator codes for the special functions, all others are handled elsewhere,
518525
// hence the IFK::None entries in the table.
519-
using IFK = IntrinsicFunctionKind;
520526
static IFK Basic[36] = {
521527
IFK::None, // ?0 # Foo::Foo()
522528
IFK::None, // ?1 # Foo::~Foo()

‎llvm/test/Demangle/invalid-manglings.test

+5
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,8 @@
109109
; CHECK-EMPTY:
110110
; CHECK-NEXT: ?x@@3PAW
111111
; CHECK-NEXT: error: Invalid mangled name
112+
113+
??}
114+
; CHECK-EMPTY:
115+
; CHECK-NEXT: ??}
116+
; CHECK-NEXT: error: Invalid mangled name

0 commit comments

Comments
 (0)
Please sign in to comment.