[demangler] Respect try_to_parse_template_args

Fixes an exponential parse found by oss-fuzz.

llvm-svn: 307941
This commit is contained in:
Erik Pilkington 2017-07-13 19:37:37 +00:00
parent 1d2dc681b1
commit 28a4d0b981
2 changed files with 14 additions and 10 deletions

View File

@ -2364,17 +2364,20 @@ parse_type(const char* first, const char* last, Db& db)
first = t;
// Parsed a substitution. If the substitution is a
// <template-param> it might be followed by <template-args>.
t = parse_template_args(first, last, db);
if (t != first)
if (db.try_to_parse_template_args)
{
if (db.names.size() < 2)
return first;
auto template_args = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += template_args;
// Need to create substitution for <template-template-param> <template-args>
db.subs.push_back(Db::sub_type(1, db.names.back(), db.names.get_allocator()));
first = t;
t = parse_template_args(first, last, db);
if (t != first)
{
if (db.names.size() < 2)
return first;
auto template_args = db.names.back().move_full();
db.names.pop_back();
db.names.back().first += template_args;
// Need to create substitution for <template-template-param> <template-args>
db.subs.push_back(Db::sub_type(1, db.names.back(), db.names.get_allocator()));
first = t;
}
}
}
}

View File

@ -29669,6 +29669,7 @@ const char* invalid_cases[] =
"_ZcvCiIJEEDvT__FFFFT_vT_v",
"Z1JIJ1_T_EE3o00EUlT_E0",
"___Z2i_D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D1D",
"ZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIDv_ZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIDv_ZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIDv_Dv_Dv_Dv_Dv_dZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIDv_ZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIDv_ZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIZcvSdIDv_Dv_Dv_Dv_Dv_d",
};
const unsigned NI = sizeof(invalid_cases) / sizeof(invalid_cases[0]);