mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-27 15:32:10 +08:00
minidump: stronger checking for MinidumpWritableAtRVA<>().
MinidumpWritableAtRVA<>() now checks that the object of the requested type is actually in the range of the minidump file’s size, rather than just checking that the beginning of the object is in range. TEST=minidump_test R=rsesek@chromium.org Review URL: https://codereview.chromium.org/708803002
This commit is contained in:
parent
48b1964d1b
commit
8ad3beccdb
@ -23,6 +23,20 @@
|
||||
namespace crashpad {
|
||||
namespace test {
|
||||
|
||||
namespace {
|
||||
|
||||
//! \brief Returns an untyped minidump object located within a minidump file’s
|
||||
//! contents, where the offset of the object is known.
|
||||
//!
|
||||
//! \param[in] file_contents The contents of the minidump file.
|
||||
//! \param[in] rva The offset within the minidump file of the desired object.
|
||||
//!
|
||||
//! \return If \a rva is within the range of \a file_contents, returns a pointer
|
||||
//! into \a file_contents at offset \a rva. Otherwise, raises a gtest
|
||||
//! assertion failure and returns `nullptr`.
|
||||
//!
|
||||
//! Do not call this function. Use the typed version, MinidumpWritableAtRVA<>(),
|
||||
//! or another type-specific function.
|
||||
const void* MinidumpWritableAtRVAInternal(const std::string& file_contents,
|
||||
RVA rva) {
|
||||
if (rva >= file_contents.size()) {
|
||||
@ -33,6 +47,8 @@ const void* MinidumpWritableAtRVAInternal(const std::string& file_contents,
|
||||
return &file_contents[rva];
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const void* MinidumpWritableAtLocationDescriptorInternal(
|
||||
const std::string& file_contents,
|
||||
const MINIDUMP_LOCATION_DESCRIPTOR& location,
|
||||
|
@ -26,23 +26,6 @@
|
||||
namespace crashpad {
|
||||
namespace test {
|
||||
|
||||
//! \brief Returns an untyped minidump object located within a minidump file’s
|
||||
//! contents, where the offset of the object is known.
|
||||
//!
|
||||
//! \param[in] file_contents The contents of the minidump file.
|
||||
//! \param[in] rva The offset within the minidump file of the desired object.
|
||||
//!
|
||||
//! \return If \a rva is within the range of \a file_contents, returns a pointer
|
||||
//! into \a file_contents at offset \a rva. Otherwise, raises a gtest
|
||||
//! assertion failure and returns `nullptr`.
|
||||
//!
|
||||
//! Do not call this function. Use the typed version, MinidumpWritableAtRVA<>(),
|
||||
//! or another type-specific function.
|
||||
//!
|
||||
//! \sa MinidumpWritableAtLocationDescriptorInternal()
|
||||
const void* MinidumpWritableAtRVAInternal(const std::string& file_contents,
|
||||
RVA rva);
|
||||
|
||||
//! \brief Returns an untyped minidump object located within a minidump file’s
|
||||
//! contents, where the offset and size of the object are known.
|
||||
//!
|
||||
@ -64,8 +47,6 @@ const void* MinidumpWritableAtRVAInternal(const std::string& file_contents,
|
||||
//!
|
||||
//! Do not call this function. Use the typed version,
|
||||
//! MinidumpWritableAtLocationDescriptor<>(), or another type-specific function.
|
||||
//!
|
||||
//! \sa MinidumpWritableAtRVAInternal()
|
||||
const void* MinidumpWritableAtLocationDescriptorInternal(
|
||||
const std::string& file_contents,
|
||||
const MINIDUMP_LOCATION_DESCRIPTOR& location,
|
||||
@ -119,23 +100,6 @@ MINIDUMP_ALLOW_OVERSIZED_DATA(uint8_t);
|
||||
|
||||
#undef MINIDUMP_ALLOW_OVERSIZED_DATA
|
||||
|
||||
//! \brief Returns a typed minidump object located within a minidump file’s
|
||||
//! contents, where the offset of the object is known.
|
||||
//!
|
||||
//! \param[in] file_contents The contents of the minidump file.
|
||||
//! \param[in] rva The offset within the minidump file of the desired object.
|
||||
//!
|
||||
//! \return If \a rva is within the range of \a file_contents, returns a pointer
|
||||
//! into \a file_contents at offset \a rva. Otherwise, raises a gtest
|
||||
//! assertion failure and returns `nullptr`.
|
||||
//!
|
||||
//! \sa MinidumpWritableAtLocationDescriptor<>()
|
||||
template <typename T>
|
||||
const T* MinidumpWritableAtRVA(const std::string& file_contents, RVA rva) {
|
||||
return reinterpret_cast<const T*>(
|
||||
MinidumpWritableAtRVAInternal(file_contents, rva));
|
||||
}
|
||||
|
||||
//! \brief Returns a typed minidump object located within a minidump file’s
|
||||
//! contents, where the offset and size of the object are known.
|
||||
//!
|
||||
@ -241,6 +205,26 @@ MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
|
||||
const std::string& file_contents,
|
||||
const MINIDUMP_LOCATION_DESCRIPTOR& location);
|
||||
|
||||
//! \brief Returns a typed minidump object located within a minidump file’s
|
||||
//! contents, where the offset of the object is known.
|
||||
//!
|
||||
//! \param[in] file_contents The contents of the minidump file.
|
||||
//! \param[in] rva The offset within the minidump file of the desired object.
|
||||
//!
|
||||
//! \return If \a rva plus the size of an object of type \a T is within the
|
||||
//! range of \a file_contents, returns a pointer into \a file_contents at
|
||||
//! offset \a rva. Otherwise, raises a gtest assertion failure and returns
|
||||
//! `nullptr`.
|
||||
//!
|
||||
//! \sa MinidumpWritableAtLocationDescriptor<>()
|
||||
template <typename T>
|
||||
const T* MinidumpWritableAtRVA(const std::string& file_contents, RVA rva) {
|
||||
MINIDUMP_LOCATION_DESCRIPTOR location;
|
||||
location.DataSize = sizeof(T);
|
||||
location.Rva = rva;
|
||||
return MinidumpWritableAtLocationDescriptor<T>(file_contents, location);
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace crashpad
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user