From 7bebb27fb44920f189310985d96ed7801f59afbb Mon Sep 17 00:00:00 2001 From: "erikchen@chromium.org" Date: Tue, 27 Jan 2015 01:20:59 +0000 Subject: 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 --- src/common/dwarf_cu_to_module.cc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/common/dwarf_cu_to_module.cc') 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(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 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 = ""; } - func->address = low_pc_; + + // Create a Module::Function based on the data we've gathered, and + // add it to the functions_ list. + scoped_ptr 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(); -- cgit v1.2.1