aboutsummaryrefslogtreecommitdiff
path: root/src/common/dwarf_cu_to_module.cc
diff options
context:
space:
mode:
authorerikchen@chromium.org <erikchen@chromium.org>2015-01-27 01:20:59 +0000
committererikchen@chromium.org <erikchen@chromium.org>2015-01-27 01:20:59 +0000
commit7bebb27fb44920f189310985d96ed7801f59afbb (patch)
tree4488552decfc8604e6d4609ba5d56c81baa1e863 /src/common/dwarf_cu_to_module.cc
parentFix a source of memory corruption. (diff)
downloadbreakpad-7bebb27fb44920f189310985d96ed7801f59afbb.tar.xz
Fix some fragile code that is likely to cause future memory corruption
problems. - The ordering of keys in stl containers cannot change. Make the relevant members const to guarantee this assumption. - Add handling and logging for demangle errors. - Fix a potential double-delete bug if a function passed to AddFunction() is already present. BUG=chromium:449214 R=mark@chromium.org Review URL: https://breakpad.appspot.com/10704002/ git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1415 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/common/dwarf_cu_to_module.cc')
-rw-r--r--src/common/dwarf_cu_to_module.cc28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/common/dwarf_cu_to_module.cc b/src/common/dwarf_cu_to_module.cc
index 4bd7bdd5..aaac058b 100644
--- a/src/common/dwarf_cu_to_module.cc
+++ b/src/common/dwarf_cu_to_module.cc
@@ -351,9 +351,15 @@ void DwarfCUToModule::GenericDIEHandler::ProcessAttributeString(
break;
case dwarf2reader::DW_AT_MIPS_linkage_name: {
char* demangled = NULL;
+ int status = -1;
#if !defined(__ANDROID__)
- demangled = abi::__cxa_demangle(data.c_str(), NULL, NULL, NULL);
+ demangled = abi::__cxa_demangle(data.c_str(), NULL, NULL, &status);
#endif
+ if (status != 0) {
+ cu_context_->reporter->DemangleError(data, status);
+ demangled_name_ = "";
+ break;
+ }
if (demangled) {
demangled_name_ = AddStringToPool(demangled);
free(reinterpret_cast<void*>(demangled));
@@ -534,18 +540,19 @@ void DwarfCUToModule::FuncHandler::Finish() {
// functions that were never used), but all the ones we're
// interested in cover a non-empty range of bytes.
if (low_pc_ < high_pc_) {
- // Create a Module::Function based on the data we've gathered, and
- // add it to the functions_ list.
- scoped_ptr<Module::Function> func(new Module::Function);
// Malformed DWARF may omit the name, but all Module::Functions must
// have names.
+ string name;
if (!name_.empty()) {
- func->name = name_;
+ name = name_;
} else {
cu_context_->reporter->UnnamedFunction(offset_);
- func->name = "<name omitted>";
+ name = "<name omitted>";
}
- func->address = low_pc_;
+
+ // Create a Module::Function based on the data we've gathered, and
+ // add it to the functions_ list.
+ scoped_ptr<Module::Function> func(new Module::Function(name, low_pc_));
func->size = high_pc_ - low_pc_;
func->parameter_size = 0;
if (func->address) {
@@ -667,6 +674,13 @@ void DwarfCUToModule::WarningReporter::UnnamedFunction(uint64 offset) {
filename_.c_str(), offset);
}
+void DwarfCUToModule::WarningReporter::DemangleError(
+ const string &input, int error) {
+ CUHeading();
+ fprintf(stderr, "%s: warning: failed to demangle %s with error %d\n",
+ filename_.c_str(), input.c_str(), error);
+}
+
void DwarfCUToModule::WarningReporter::UnhandledInterCUReference(
uint64 offset, uint64 target) {
CUHeading();