From d6da74f22b851d210158c606972a6a2186174633 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 14 Nov 2016 04:54:47 +0000 Subject: [PATCH] Demangle: only demangle mangled symbols Only attempt to demangle symbols which have the itanium C++ prefix of `_Z`. This ensures that we do not treat any symbol name as a managled named. We would previously treat a C function `f` as a mangled name and decode that to `float` incorrectly. While it is easy to add tests for this, Mehdi recommended against introducing tests for the demangler as libc++abi should cover the testing. llvm-svn: 286795 --- llvm/lib/Demangle/ItaniumDemangle.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Demangle/ItaniumDemangle.cpp b/llvm/lib/Demangle/ItaniumDemangle.cpp index 1d3080c7cb81..39598aad649f 100644 --- a/llvm/lib/Demangle/ItaniumDemangle.cpp +++ b/llvm/lib/Demangle/ItaniumDemangle.cpp @@ -4252,6 +4252,16 @@ char *llvm::itaniumDemangle(const char *mangled_name, char *buf, size_t *n, *status = invalid_args; return nullptr; } + + size_t len = std::strlen(mangled_name); + if (len < 2 || strncmp(mangled_name, "_Z", 2)) { + if (len < 4 || strncmp(mangled_name, "___Z", 4)) { + if (status) + *status = invalid_mangled_name; + return nullptr; + } + } + size_t internal_size = buf != nullptr ? *n : 0; Db db; db.cv = 0; @@ -4263,7 +4273,6 @@ char *llvm::itaniumDemangle(const char *mangled_name, char *buf, size_t *n, db.fix_forward_references = false; db.try_to_parse_template_args = true; int internal_status = success; - size_t len = std::strlen(mangled_name); demangle(mangled_name, mangled_name + len, db, internal_status); if (internal_status == success && db.fix_forward_references && !db.template_param.empty() && !db.template_param.front().empty()) { -- 2.34.1