summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2019-04-11 23:11:33 +0000
committerNico Weber <nicolasweber@gmx.de>2019-04-11 23:11:33 +0000
commit03db625c1387940624fcb0ca6be56eaed6ccf192 (patch)
tree50ecebc020e0cff37762142f222866f97846f8f6
parente5b62654a5df4d51d65f4ffd9daf1057e1255a6e (diff)
downloadbcm5719-llvm-03db625c1387940624fcb0ca6be56eaed6ccf192.tar.gz
bcm5719-llvm-03db625c1387940624fcb0ca6be56eaed6ccf192.zip
llvm-undname: Fix out-of-bounds read on invalid intrinsic function code
Found by inspection. llvm-svn: 358239
-rw-r--r--llvm/include/llvm/Demangle/MicrosoftDemangle.h2
-rw-r--r--llvm/lib/Demangle/MicrosoftDemangle.cpp12
-rw-r--r--llvm/test/Demangle/invalid-manglings.test5
3 files changed, 16 insertions, 3 deletions
diff --git a/llvm/include/llvm/Demangle/MicrosoftDemangle.h b/llvm/include/llvm/Demangle/MicrosoftDemangle.h
index 66553b4b250..442c41d6fd3 100644
--- a/llvm/include/llvm/Demangle/MicrosoftDemangle.h
+++ b/llvm/include/llvm/Demangle/MicrosoftDemangle.h
@@ -207,6 +207,8 @@ private:
NamedIdentifierNode *demangleBackRefName(StringView &MangledName);
IdentifierNode *demangleTemplateInstantiationName(StringView &MangledName,
NameBackrefBehavior NBB);
+ IntrinsicFunctionKind
+ translateIntrinsicFunctionCode(char CH, FunctionIdentifierCodeGroup Group);
IdentifierNode *demangleFunctionIdentifierCode(StringView &MangledName);
IdentifierNode *
demangleFunctionIdentifierCode(StringView &MangledName,
diff --git a/llvm/lib/Demangle/MicrosoftDemangle.cpp b/llvm/lib/Demangle/MicrosoftDemangle.cpp
index c4559ccb5e2..0c3602a4a4c 100644
--- a/llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ b/llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -511,12 +511,18 @@ Demangler::demangleLiteralOperatorIdentifier(StringView &MangledName) {
return N;
}
-static IntrinsicFunctionKind
-translateIntrinsicFunctionCode(char CH, FunctionIdentifierCodeGroup Group) {
+IntrinsicFunctionKind
+Demangler::translateIntrinsicFunctionCode(char CH,
+ FunctionIdentifierCodeGroup Group) {
+ using IFK = IntrinsicFunctionKind;
+ if (!(CH >= '0' && CH <= '9') && !(CH >= 'A' && CH <= 'Z')) {
+ Error = true;
+ return IFK::None;
+ }
+
// Not all ? identifiers are intrinsics *functions*. This function only maps
// operator codes for the special functions, all others are handled elsewhere,
// hence the IFK::None entries in the table.
- using IFK = IntrinsicFunctionKind;
static IFK Basic[36] = {
IFK::None, // ?0 # Foo::Foo()
IFK::None, // ?1 # Foo::~Foo()
diff --git a/llvm/test/Demangle/invalid-manglings.test b/llvm/test/Demangle/invalid-manglings.test
index 839218ad101..473b3e4bbe1 100644
--- a/llvm/test/Demangle/invalid-manglings.test
+++ b/llvm/test/Demangle/invalid-manglings.test
@@ -109,3 +109,8 @@
; CHECK-EMPTY:
; CHECK-NEXT: ?x@@3PAW
; CHECK-NEXT: error: Invalid mangled name
+
+??}
+; CHECK-EMPTY:
+; CHECK-NEXT: ??}
+; CHECK-NEXT: error: Invalid mangled name
OpenPOWER on IntegriCloud