Author: compnerd Date: Sun Nov 13 19:55:54 2016 New Revision: 286788 URL: http://llvm.org/viewvc/llvm-project?rev=286788&view=rev Log: __cxa_demangle: ensure that we have a mangled symbol
Ensure that we have a mangled symbol before attempting to demangle it. We would previously treat any input as a mangled symbol rather than checking that the symbol has the initial C++ Itanium v3 mangling prefix of `_Z`. This changes the behaviour from the previous case which would undecorate `f` to `float` rather than nullptr as it should. Unfortunately, we do not have any negative testing for the demangler. Modified: libcxxabi/trunk/src/cxa_demangle.cpp Modified: libcxxabi/trunk/src/cxa_demangle.cpp URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_demangle.cpp?rev=286788&r1=286787&r2=286788&view=diff ============================================================================== --- libcxxabi/trunk/src/cxa_demangle.cpp (original) +++ libcxxabi/trunk/src/cxa_demangle.cpp Sun Nov 13 19:55:54 2016 @@ -4978,6 +4978,15 @@ __cxa_demangle(const char *mangled_name, *status = invalid_args; return nullptr; } + + size_t len = std::strlen(mangled_name); + if (len < 2 || mangled_name[0] != '_' || mangled_name[1] != 'Z') + { + if (status) + *status = invalid_mangled_name; + return nullptr; + } + size_t internal_size = buf != nullptr ? *n : 0; arena<bs> a; Db db(a); @@ -4990,7 +4999,6 @@ __cxa_demangle(const char *mangled_name, 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 && _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits