From 5cc158e9a90083ba769d6f9d590c308e080394d5 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Sat, 16 May 2015 16:49:46 +0000 Subject: [PATCH] d-demangle.c (dlang_identifier): Check encoded length of identifier to verify strncmp matches entire string. libiberty/ChangeLog: 2015-05-16 Iain Buclaw * d-demangle.c (dlang_identifier): Check encoded length of identifier to verify strncmp matches entire string. * testsuite/d-demangle-expected: Fix wrong test for postblit symbol. From-SVN: r223243 --- libiberty/ChangeLog | 6 ++ libiberty/d-demangle.c | 133 +++++++++++++----------- libiberty/testsuite/d-demangle-expected | 2 +- 3 files changed, 82 insertions(+), 59 deletions(-) diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 3eac5226392..37425c8df81 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,9 @@ +2015-05-16 Iain Buclaw + + * d-demangle.c (dlang_identifier): Check encoded length of identifier + to verify strncmp matches entire string. + * testsuite/d-demangle-expected: Fix wrong test for postblit symbol. + 2015-05-16 Iain Buclaw * d-demangle.c (dlang_type_modifiers): New function. diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c index 98e81606b58..011e62bc662 100644 --- a/libiberty/d-demangle.c +++ b/libiberty/d-demangle.c @@ -672,65 +672,82 @@ dlang_identifier (string *decl, const char *mangled) return NULL; } - if (strncmp (mangled, "__ctor", i) == 0) + switch (i) { - /* Constructor symbol for a class/struct. */ - string_append (decl, "this"); - mangled += i; - return mangled; - } - else if (strncmp (mangled, "__dtor", i) == 0) - { - /* Destructor symbol for a class/struct. */ - string_append (decl, "~this"); - mangled += i; - return mangled; - } - else if (strncmp (mangled, "__postblit", i) == 0) - { - /* Postblit symbol for a struct. */ - string_append (decl, "this(this)"); - mangled += i; - return mangled; - } - else if (strncmp (mangled, "__initZ", i+1) == 0) - { - /* The static initialiser for a given symbol. */ - string_append (decl, "init$"); - mangled += i + 1; - return mangled; - } - else if (strncmp (mangled, "__ClassZ", i+1) == 0) - { - /* The classinfo symbol for a given class. */ - string_prepend (decl, "ClassInfo for "); - string_setlength (decl, string_length (decl) - 1); - mangled += i + 1; - return mangled; - } - else if (strncmp (mangled, "__vtblZ", i+1) == 0) - { - /* The vtable symbol for a given class. */ - string_prepend (decl, "vtable for "); - string_setlength (decl, string_length (decl) - 1); - mangled += i + 1; - return mangled; - } - else if (strncmp (mangled, "__InterfaceZ", i+1) == 0) - { - /* The interface symbol for a given class. */ - string_prepend (decl, "Interface for "); - string_setlength (decl, string_length (decl) - 1); - mangled += i + 1; - return mangled; - } - else if (strncmp (mangled, "__ModuleInfoZ", i+1) == 0) - { - /* The ModuleInfo symbol for a given module. */ - string_prepend (decl, "ModuleInfo for "); - string_setlength (decl, string_length (decl) - 1); - mangled += i + 1; - return mangled; + case 6: + if (strncmp (mangled, "__ctor", i) == 0) + { + /* Constructor symbol for a class/struct. */ + string_append (decl, "this"); + mangled += i; + return mangled; + } + else if (strncmp (mangled, "__dtor", i) == 0) + { + /* Destructor symbol for a class/struct. */ + string_append (decl, "~this"); + mangled += i; + return mangled; + } + else if (strncmp (mangled, "__initZ", i+1) == 0) + { + /* The static initialiser for a given symbol. */ + string_append (decl, "init$"); + mangled += i; + return mangled; + } + else if (strncmp (mangled, "__vtblZ", i+1) == 0) + { + /* The vtable symbol for a given class. */ + string_prepend (decl, "vtable for "); + string_setlength (decl, string_length (decl) - 1); + mangled += i; + return mangled; + } + break; + + case 7: + if (strncmp (mangled, "__ClassZ", i+1) == 0) + { + /* The classinfo symbol for a given class. */ + string_prepend (decl, "ClassInfo for "); + string_setlength (decl, string_length (decl) - 1); + mangled += i; + return mangled; + } + break; + + case 10: + if (strncmp (mangled, "__postblitMFZ", i+3) == 0) + { + /* Postblit symbol for a struct. */ + string_append (decl, "this(this)"); + mangled += i + 3; + return mangled; + } + break; + + case 11: + if (strncmp (mangled, "__InterfaceZ", i+1) == 0) + { + /* The interface symbol for a given class. */ + string_prepend (decl, "Interface for "); + string_setlength (decl, string_length (decl) - 1); + mangled += i; + return mangled; + } + break; + + case 12: + if (strncmp (mangled, "__ModuleInfoZ", i+1) == 0) + { + /* The ModuleInfo symbol for a given module. */ + string_prepend (decl, "ModuleInfo for "); + string_setlength (decl, string_length (decl) - 1); + mangled += i; + return mangled; + } + break; } string_appendn (decl, mangled, i); diff --git a/libiberty/testsuite/d-demangle-expected b/libiberty/testsuite/d-demangle-expected index 80445066e72..b0b9ca0b49d 100644 --- a/libiberty/testsuite/d-demangle-expected +++ b/libiberty/testsuite/d-demangle-expected @@ -502,7 +502,7 @@ _D8demangle4test6__dtorMFZv demangle.test.~this() # --format=dlang -_D8demangle4test6__postblitMFZv +_D8demangle4test10__postblitMFZv demangle.test.this(this) # --format=dlang -- 2.30.2