From 8c7262afc39dbf7a63a54e8518623131803a4c1a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 1 Jul 2005 16:39:36 +0000 Subject: [PATCH] re PR other/22268 (libiberty demanger crashes on (invalid) mangled name) PR other/22268 * cp-demangle.c (d_expr_primary): Don't run off the end of the string while looking for the end of a literal value. * testsuite/demangle-expected: Add test case. From-SVN: r101506 --- libiberty/ChangeLog | 7 +++++++ libiberty/cp-demangle.c | 6 +++++- libiberty/testsuite/demangle-expected | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index 2522b8270e6..eb19aa71e4c 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,10 @@ +2005-07-01 Ian Lance Taylor + + PR other/22268 + * cp-demangle.c (d_expr_primary): Don't run off the end of the + string while looking for the end of a literal value. + * testsuite/demangle-expected: Add test case. + 2005-06-30 Daniel Berlin * hashtab.c (EMPTY_ENTRY): Moved and renamed. diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index 61744390725..8f1cfb17f87 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -2337,7 +2337,11 @@ d_expr_primary (struct d_info *di) } s = d_str (di); while (d_peek_char (di) != 'E') - d_advance (di, 1); + { + if (d_peek_char (di) == '\0') + return NULL; + d_advance (di, 1); + } ret = d_make_comp (di, t, type, d_make_name (di, s, d_str (di) - s)); } if (d_next_char (di) != 'E') diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected index f8e402d01bd..4526773a780 100644 --- a/libiberty/testsuite/demangle-expected +++ b/libiberty/testsuite/demangle-expected @@ -3704,6 +3704,12 @@ foo _ZN13PatternDriver23StringScalarDeleteValueC1ERKNS_25ConflateStringScalarValueERKNS_25AbstractStringScalarValueERKNS_12TemplateEnumINS_12pdcomplementELZNS_16complement_namesEELZNS_14COMPLEMENTENUMEEEE _ZN13PatternDriver23StringScalarDeleteValueC1ERKNS_25ConflateStringScalarValueERKNS_25AbstractStringScalarValueERKNS_12TemplateEnumINS_12pdcomplementELZNS_16complement_namesEELZNS_14COMPLEMENTENUMEEEE PatternDriver::StringScalarDeleteValue::StringScalarDeleteValue +# +# This used to cause the demangler to walk into undefined memory--PR 22268 +--format=gnu-v3 --no-params +ALsetchannels +ALsetchannels +ALsetchannels # Test GNU V3 constructor and destructor identification. # 0 means it is not a constructor/destructor. # Other integers correspond to enum gnu_v3_{c,d}tor_kinds in demangle.h.