diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-11-14 01:55:54 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-11-14 01:55:54 +0000 |
commit | 8cfa5a3ce80feee59b7790258ae254c291c3a2a6 (patch) | |
tree | 110c9149e9bf91130a18e3302ca4382c7a267992 /src | |
parent | 110520227e841104d38f826174302ff7068b2611 (diff) |
__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.
git-svn-id: https://llvm.org/svn/llvm-project/libcxxabi/trunk@286788 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'src')
-rw-r--r-- | src/cxa_demangle.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/cxa_demangle.cpp b/src/cxa_demangle.cpp index 25aa741..8b9dfc9 100644 --- a/src/cxa_demangle.cpp +++ b/src/cxa_demangle.cpp @@ -4978,6 +4978,15 @@ __cxa_demangle(const char *mangled_name, char *buf, size_t *n, int *status) { *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, char *buf, size_t *n, int *status) { 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 && |