Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: src/processor/minidump.cc

Issue 1271543002: Fix potential null pointer dereference. (Closed) Base URL: http://google-breakpad.googlecode.com/svn/trunk/
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/google_breakpad/processor/minidump.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 Google Inc. 1 // Copyright (c) 2010 Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 3981 matching lines...) Expand 10 before | Expand all | Expand 10 after
3992 // MinidumpLinuxMapsList 3992 // MinidumpLinuxMapsList
3993 // 3993 //
3994 3994
3995 MinidumpLinuxMapsList::MinidumpLinuxMapsList(Minidump *minidump) 3995 MinidumpLinuxMapsList::MinidumpLinuxMapsList(Minidump *minidump)
3996 : MinidumpStream(minidump), 3996 : MinidumpStream(minidump),
3997 maps_(NULL), 3997 maps_(NULL),
3998 maps_count_(0) { 3998 maps_count_(0) {
3999 } 3999 }
4000 4000
4001 MinidumpLinuxMapsList::~MinidumpLinuxMapsList() { 4001 MinidumpLinuxMapsList::~MinidumpLinuxMapsList() {
4002 for (unsigned int i = 0; i < maps_->size(); i++) { 4002 if (maps_) {
4003 delete (*maps_)[i]; 4003 for (unsigned int i = 0; i < maps_->size(); i++) {
4004 delete (*maps_)[i];
4005 }
4006 delete maps_;
4004 } 4007 }
4005 delete maps_;
4006 } 4008 }
4007 4009
4008 const MinidumpLinuxMaps *MinidumpLinuxMapsList::GetLinuxMapsForAddress( 4010 const MinidumpLinuxMaps *MinidumpLinuxMapsList::GetLinuxMapsForAddress(
4009 uint64_t address) const { 4011 uint64_t address) const {
4010 if (!valid_) { 4012 if (!valid_ || (maps_ == NULL)) {
4011 BPLOG(ERROR) << "Invalid MinidumpLinuxMapsList for GetLinuxMapsForAddress"; 4013 BPLOG(ERROR) << "Invalid MinidumpLinuxMapsList for GetLinuxMapsForAddress";
4012 return NULL; 4014 return NULL;
4013 } 4015 }
4014 4016
4015 // Search every memory mapping. 4017 // Search every memory mapping.
4016 for (unsigned int index = 0; index < maps_count_; index++) { 4018 for (unsigned int index = 0; index < maps_count_; index++) {
4017 // Check if address is within bounds of the current memory region. 4019 // Check if address is within bounds of the current memory region.
4018 if ((*maps_)[index]->GetBase() <= address && 4020 if ((*maps_)[index]->GetBase() <= address &&
4019 (*maps_)[index]->GetBase() + (*maps_)[index]->GetSize() > address) { 4021 (*maps_)[index]->GetBase() + (*maps_)[index]->GetSize() > address) {
4020 return (*maps_)[index]; 4022 return (*maps_)[index];
4021 } 4023 }
4022 } 4024 }
4023 4025
4024 // No mapping encloses the memory address. 4026 // No mapping encloses the memory address.
4025 BPLOG(ERROR) << "MinidumpLinuxMapsList has no mapping at " 4027 BPLOG(ERROR) << "MinidumpLinuxMapsList has no mapping at "
4026 << HexString(address); 4028 << HexString(address);
4027 return NULL; 4029 return NULL;
4028 } 4030 }
4029 4031
4030 const MinidumpLinuxMaps *MinidumpLinuxMapsList::GetLinuxMapsAtIndex( 4032 const MinidumpLinuxMaps *MinidumpLinuxMapsList::GetLinuxMapsAtIndex(
4031 unsigned int index) const { 4033 unsigned int index) const {
4032 if (!valid_) { 4034 if (!valid_ || (maps_ == NULL)) {
4033 BPLOG(ERROR) << "Invalid MinidumpLinuxMapsList for GetLinuxMapsAtIndex"; 4035 BPLOG(ERROR) << "Invalid MinidumpLinuxMapsList for GetLinuxMapsAtIndex";
4034 return NULL; 4036 return NULL;
4035 } 4037 }
4036 4038
4037 // Index out of bounds. 4039 // Index out of bounds.
4038 if (index >= maps_count_) { 4040 if (index >= maps_count_ || (maps_ == NULL)) {
4039 BPLOG(ERROR) << "MinidumpLinuxMapsList index of out range: " 4041 BPLOG(ERROR) << "MinidumpLinuxMapsList index of out range: "
4040 << index 4042 << index
4041 << "/" 4043 << "/"
4042 << maps_count_; 4044 << maps_count_;
4043 return NULL; 4045 return NULL;
4044 } 4046 }
4045 return (*maps_)[index]; 4047 return (*maps_)[index];
4046 } 4048 }
4047 4049
4048 bool MinidumpLinuxMapsList::Read(uint32_t expected_size) { 4050 bool MinidumpLinuxMapsList::Read(uint32_t expected_size) {
4049 // Invalidate cached data. 4051 // Invalidate cached data.
4050 delete maps_; 4052 if (maps_) {
4053 for (unsigned int i = 0; i < maps_->size(); i++) {
4054 delete (*maps_)[i];
4055 }
4056 delete maps_;
4057 }
4051 maps_ = NULL; 4058 maps_ = NULL;
4052 maps_count_ = 0; 4059 maps_count_ = 0;
4053 4060
4054 valid_ = false; 4061 valid_ = false;
4055 4062
4056 // Load and check expected stream length. 4063 // Load and check expected stream length.
4057 uint32_t length = 0; 4064 uint32_t length = 0;
4058 if (!minidump_->SeekToStreamType(MD_LINUX_MAPS, &length)) { 4065 if (!minidump_->SeekToStreamType(MD_LINUX_MAPS, &length)) {
4059 BPLOG(ERROR) << "MinidumpLinuxMapsList stream type not found"; 4066 BPLOG(ERROR) << "MinidumpLinuxMapsList stream type not found";
4060 return false; 4067 return false;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4093 } 4100 }
4094 4101
4095 // Set instance variables. 4102 // Set instance variables.
4096 maps_ = maps.release(); 4103 maps_ = maps.release();
4097 maps_count_ = maps_->size(); 4104 maps_count_ = maps_->size();
4098 valid_ = true; 4105 valid_ = true;
4099 return true; 4106 return true;
4100 } 4107 }
4101 4108
4102 void MinidumpLinuxMapsList::Print() { 4109 void MinidumpLinuxMapsList::Print() {
4103 if (!valid_) { 4110 if (!valid_ || (maps_ == NULL)) {
4104 BPLOG(ERROR) << "MinidumpLinuxMapsList cannot print valid data"; 4111 BPLOG(ERROR) << "MinidumpLinuxMapsList cannot print valid data";
4105 return; 4112 return;
4106 } 4113 }
4107 for (size_t i = 0; i < maps_->size(); i++) { 4114 for (size_t i = 0; i < maps_->size(); i++) {
4108 (*maps_)[i]->Print(); 4115 (*maps_)[i]->Print();
4109 } 4116 }
4110 } 4117 }
4111 4118
4112 // 4119 //
4113 // Minidump 4120 // Minidump
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
4763 return NULL; 4770 return NULL;
4764 } 4771 }
4765 4772
4766 *stream = new_stream.release(); 4773 *stream = new_stream.release();
4767 info->stream = *stream; 4774 info->stream = *stream;
4768 return *stream; 4775 return *stream;
4769 } 4776 }
4770 4777
4771 4778
4772 } // namespace google_breakpad 4779 } // namespace google_breakpad
OLDNEW
« no previous file with comments | « src/google_breakpad/processor/minidump.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698