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

Unified Diff: snapshot/win/pe_image_reader.cc

Issue 1411123011: win: Don't attempt to read a nonexistent IMAGE_DIRECTORY_ENTRY_DEBUG (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « snapshot/win/pe_image_reader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: snapshot/win/pe_image_reader.cc
diff --git a/snapshot/win/pe_image_reader.cc b/snapshot/win/pe_image_reader.cc
index 7268358a056eaedd1091a76ca939ecac0e00db23..6f5bb61086cfb930b79c4fab9c9f8ea5eb83a996 100644
--- a/snapshot/win/pe_image_reader.cc
+++ b/snapshot/win/pe_image_reader.cc
@@ -143,10 +143,19 @@ template <class NtHeadersType>
bool PEImageReader::ReadDebugDirectoryInformation(UUID* uuid,
DWORD* age,
std::string* pdbname) const {
- WinVMAddress nt_headers_address;
NtHeadersType nt_headers;
- if (!ReadNtHeaders(&nt_headers_address, &nt_headers))
+ if (!ReadNtHeaders(&nt_headers, nullptr))
+ return false;
+
+ if (nt_headers.FileHeader.SizeOfOptionalHeader <
+ offsetof(decltype(nt_headers.OptionalHeader),
+ DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG]) +
+ sizeof(nt_headers.OptionalHeader
+ .DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG]) ||
+ nt_headers.OptionalHeader.NumberOfRvaAndSizes <=
+ IMAGE_DIRECTORY_ENTRY_DEBUG) {
return false;
+ }
const IMAGE_DATA_DIRECTORY& data_directory =
nt_headers.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG];
@@ -202,8 +211,8 @@ bool PEImageReader::ReadDebugDirectoryInformation(UUID* uuid,
}
template <class NtHeadersType>
-bool PEImageReader::ReadNtHeaders(WinVMAddress* nt_headers_address,
- NtHeadersType* nt_headers) const {
+bool PEImageReader::ReadNtHeaders(NtHeadersType* nt_headers,
+ WinVMAddress* nt_headers_address) const {
IMAGE_DOS_HEADER dos_header;
if (!CheckedReadMemory(Address(), sizeof(IMAGE_DOS_HEADER), &dos_header)) {
LOG(WARNING) << "could not read dos header of " << module_name_;
@@ -215,9 +224,9 @@ bool PEImageReader::ReadNtHeaders(WinVMAddress* nt_headers_address,
return false;
}
- *nt_headers_address = Address() + dos_header.e_lfanew;
+ WinVMAddress local_nt_headers_address = Address() + dos_header.e_lfanew;
if (!CheckedReadMemory(
- *nt_headers_address, sizeof(NtHeadersType), nt_headers)) {
+ local_nt_headers_address, sizeof(NtHeadersType), nt_headers)) {
LOG(WARNING) << "could not read nt headers of " << module_name_;
return false;
}
@@ -227,6 +236,9 @@ bool PEImageReader::ReadNtHeaders(WinVMAddress* nt_headers_address,
return false;
}
+ if (nt_headers_address)
+ *nt_headers_address = local_nt_headers_address;
+
return true;
}
@@ -238,9 +250,9 @@ bool PEImageReader::GetSectionByName(const std::string& name,
return false;
}
- WinVMAddress nt_headers_address;
NtHeadersType nt_headers;
- if (!ReadNtHeaders(&nt_headers_address, &nt_headers))
+ WinVMAddress nt_headers_address;
+ if (!ReadNtHeaders(&nt_headers, &nt_headers_address))
return false;
WinVMAddress first_section_address =
« no previous file with comments | « snapshot/win/pe_image_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698