Commit 2f23243d authored by Will Harris's avatar Will Harris Committed by Commit Bot

Fix some 64-bit to 32-bit implicit conversions in chrome_elf.

../../chrome_elf/pe_image_safe/pe_image_safe.cc(76,75):  error: implicit conversion loses integer precision: 'long long' to 'DWORD' (aka 'unsigned long') [-Werror,-Wshorten-64-to-32]
  DWORD optional_header_offset = reinterpret_cast<char*>(optional_header) -
        ~~~~~~~~~~~~~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

../../chrome_elf/third_party_dlls/main.cc(77,54):  error: implicit conversion loses integer precision: 'std::vector<unsigned char, std::allocator<unsigned char> >::size_type' (aka 'unsigned long long') to 'DWORD' (aka 'unsigned long') [-Werror,-Wshorten-64-to-32]
                     value_bytes.data(), value_bytes.size());
                                         ~~~~~~~~~~~~^~~~~~

../../chrome_elf/third_party_dlls/logs.cc(127,46):  error: implicit conversion loses integer precision: 'unsigned long long' to 'uint32_t' (aka 'unsigned int') [-Werror,-Wshorten-64-to-32]
                            : kMaxLogEntries - entries_.size();
                              ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~

../../chrome_elf/third_party_dlls/hook.cc(283,32):  error: implicit conversion loses integer precision: 'ULONG_PTR' (aka 'unsigned long long') to 'DWORD' (aka 'unsigned long') [-Werror,-Wshorten-64-to-32]
  if (!GetDataFromImage(*base, *view_size, &time_date_stamp, &image_size,
       ~~~~~~~~~~~~~~~~        ^~~~~~~~~~

BUG=588506

Change-Id: I82abea7b741de1c56e9bcd1ce8c5bd59357ed20b
Reviewed-on: https://chromium-review.googlesource.com/1184318
Commit-Queue: Will Harris <wfh@chromium.org>
Reviewed-by: default avatarPenny MacNeil <pennymac@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585331}
parent 37254104
......@@ -73,8 +73,8 @@ BYTE* PEImageSafe::GetOptionalHeader() {
PIMAGE_OPTIONAL_HEADER optional_header =
reinterpret_cast<PIMAGE_OPTIONAL_HEADER>(
reinterpret_cast<char*>(file_header) + sizeof(IMAGE_FILE_HEADER));
DWORD optional_header_offset = reinterpret_cast<char*>(optional_header) -
reinterpret_cast<char*>(dos_header_);
uintptr_t optional_header_offset = reinterpret_cast<char*>(optional_header) -
reinterpret_cast<char*>(dos_header_);
if (optional_header_offset + sizeof(IMAGE_OPTIONAL_HEADER::Magic) >
image_size_) {
return nullptr;
......
......@@ -4,6 +4,7 @@
#include "chrome_elf/third_party_dlls/hook.h"
#include <limits>
#include <memory>
#include <assert.h>
......@@ -280,8 +281,15 @@ NTSTATUS NewNtMapViewOfSectionImpl(
std::string image_name;
std::string section_path;
std::string section_basename;
if (!GetDataFromImage(*base, *view_size, &time_date_stamp, &image_size,
&image_name, &section_path, &section_basename)) {
assert(*view_size < std::numeric_limits<DWORD>::max());
// A memory section can be > 32-bits, but an image/PE in memory can only be <=
// 32-bits in size. That's a limitation of Windows and its interactions with
// processors. No section that appears to be an image (checked above) should
// have such a large size.
if (!GetDataFromImage(*base, static_cast<DWORD>(*view_size), &time_date_stamp,
&image_size, &image_name, &section_path,
&section_basename)) {
return ret;
}
......
......@@ -122,9 +122,9 @@ class Log {
// logging events should be added via AddEntry().
void InsertAtEnd(std::vector<LogEntryInternal>::iterator first_element,
uint32_t count) {
uint32_t elements = (entries_.size() + count <= kMaxLogEntries)
? count
: kMaxLogEntries - entries_.size();
size_t elements = (entries_.size() + count <= kMaxLogEntries)
? count
: kMaxLogEntries - entries_.size();
assert(elements <= count);
if (elements)
......
......@@ -4,6 +4,8 @@
#include "chrome_elf/third_party_dlls/main.h"
#include <limits>
#include <windows.h>
#include <versionhelpers.h>
......@@ -73,8 +75,10 @@ void AddStatusCode(ThirdPartyStatus code) {
AddStatusCodeToBuffer(code, &value_bytes);
assert(value_bytes.size() < std::numeric_limits<DWORD>::max());
nt::SetRegKeyValue(key_handle, kStatusCodesRegValue, REG_BINARY,
value_bytes.data(), value_bytes.size());
value_bytes.data(),
static_cast<DWORD>(value_bytes.size()));
nt::CloseRegKey(key_handle);
return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment