Import a new libcxxrt. This fixes some potential crashing in the demangler.

Approved by:	re (gjb)
MFC after:	1 week
This commit is contained in:
David Chisnall 2013-09-23 13:16:21 +00:00
parent d19cfc0197
commit 0f9eee39f0
3 changed files with 75 additions and 18 deletions

View File

@ -405,6 +405,7 @@ static int cpp_demangle_read_expression_trinary(struct cpp_demangle_data *,
const char *, size_t, const char *, size_t);
static int cpp_demangle_read_function(struct cpp_demangle_data *, int *,
struct vector_type_qualifier *);
static int cpp_demangle_local_source_name(struct cpp_demangle_data *ddata);
static int cpp_demangle_read_local_name(struct cpp_demangle_data *);
static int cpp_demangle_read_name(struct cpp_demangle_data *);
static int cpp_demangle_read_nested_name(struct cpp_demangle_data *);
@ -453,20 +454,12 @@ __cxa_demangle_gnu3(const char *org)
struct cpp_demangle_data ddata;
ssize_t org_len;
unsigned int limit;
char *rtn;
char *rtn = NULL;
if (org == NULL)
return (NULL);
// Try demangling as a type for short encodings
if (((org_len = strlen(org)) < 2) || (org[0] != '_' || org[1] != 'Z' )) {
if (!cpp_demangle_data_init(&ddata, org))
return (NULL);
if (!cpp_demangle_read_type(&ddata, 0))
goto clean;
rtn = vector_str_get_flat(&ddata.output, (size_t *) NULL);
goto clean;
}
org_len = strlen(org);
if (org_len > 11 && !strncmp(org, "_GLOBAL__I_", 11)) {
if ((rtn = malloc(org_len + 19)) == NULL)
return (NULL);
@ -475,6 +468,16 @@ __cxa_demangle_gnu3(const char *org)
return (rtn);
}
// Try demangling as a type for short encodings
if ((org_len < 2) || (org[0] != '_' || org[1] != 'Z' )) {
if (!cpp_demangle_data_init(&ddata, org))
return (NULL);
if (!cpp_demangle_read_type(&ddata, 0))
goto clean;
rtn = vector_str_get_flat(&ddata.output, (size_t *) NULL);
goto clean;
}
if (!cpp_demangle_data_init(&ddata, org + 2))
return (NULL);
@ -604,13 +607,12 @@ cpp_demangle_push_fp(struct cpp_demangle_data *ddata,
return (0);
rtn = 0;
if ((len = strlen(f)) > 0 &&
cpp_demangle_push_str(ddata, f, len))
rtn = 1;
if ((len = strlen(f)) > 0)
rtn = cpp_demangle_push_str(ddata, f, len);
free(f);
return (0);
return (rtn);
}
static int
@ -655,6 +657,7 @@ cpp_demangle_push_subst_v(struct cpp_demangle_data *ddata, struct vector_str *v)
return (0);
rtn = cpp_demangle_push_subst(ddata, str, str_len);
free(str);
return (rtn);
@ -1868,9 +1871,18 @@ static int
cpp_demangle_read_sname(struct cpp_demangle_data *ddata)
{
long len;
int err;
if (ddata == NULL || cpp_demangle_read_number(ddata, &len) == 0 ||
len <= 0 || cpp_demangle_push_str(ddata, ddata->cur, len) == 0)
len <= 0)
return (0);
if (len == 12 && (memcmp("_GLOBAL__N_1", ddata->cur, 12) == 0))
err = cpp_demangle_push_str(ddata, "(anonymous namespace)", 21);
else
err = cpp_demangle_push_str(ddata, ddata->cur, len);
if (err == 0)
return (0);
assert(ddata->output.size > 0);
@ -2054,7 +2066,7 @@ cpp_demangle_read_subst_std(struct cpp_demangle_data *ddata)
free(subst_str);
vector_str_dest(&v);
return (1);
return (rtn);
}
static int
@ -2996,6 +3008,40 @@ cpp_demangle_read_uqname(struct cpp_demangle_data *ddata)
if (ELFTC_ISDIGIT(*ddata->cur) != 0)
return (cpp_demangle_read_sname(ddata));
/* local source name */
if (*ddata->cur == 'L')
return (cpp_demangle_local_source_name(ddata));
return (1);
}
/*
* Read local source name.
*
* References:
* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31775
* http://gcc.gnu.org/viewcvs?view=rev&revision=124467
*/
static int
cpp_demangle_local_source_name(struct cpp_demangle_data *ddata)
{
/* L */
if (ddata == NULL || *ddata->cur != 'L')
return (0);
++ddata->cur;
/* source name */
if (!cpp_demangle_read_sname(ddata))
return (0);
/* discriminator */
if (*ddata->cur == '_') {
++ddata->cur;
while (ELFTC_ISDIGIT(*ddata->cur) != 0)
++ddata->cur;
}
return (1);
}

View File

@ -86,7 +86,18 @@ extern "C" char* __cxa_demangle(const char* mangled_name,
if (NULL != demangled)
{
size_t len = strlen(demangled);
buf = (char*)realloc(buf, len+1);
if (buf == NULL)
{
if (n)
{
*n = len;
}
return demangled;
}
if (*n < len+1)
{
buf = (char*)realloc(buf, len+1);
}
if (0 != buf)
{
memcpy(buf, demangled, len);

View File

@ -80,7 +80,7 @@ struct _Unwind_Exception
_Unwind_Exception_Cleanup_Fn exception_cleanup;
unsigned long private_1;
unsigned long private_2;
};
} ;
extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,