Commit 63ee5137 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

avoid snprintf in Elf code

Summary: `snprintf` may not be async-signal-safe, but Elf code is intended for use in signal handlers.

Reviewed By: luciang

Differential Revision: D27000080

fbshipit-source-id: 818f48787b5712b7334eca782e18c71c17d03361
parent 994d82d3
...@@ -272,20 +272,16 @@ class ElfFile { ...@@ -272,20 +272,16 @@ class ElfFile {
template <class T> template <class T>
const T& at(ElfOff offset) const noexcept { const T& at(ElfOff offset) const noexcept {
static_assert(std::is_pod<T>::value, "non-pod"); static_assert(std::is_pod<T>::value, "non-pod");
if (offset + sizeof(T) > length_) { FOLLY_SAFE_CHECK(
char msg[kFilepathMaxLen + 128]; offset + sizeof(T) <= length_,
snprintf( "Offset (",
msg,
sizeof(msg),
"Offset (%zu + %zu) is not contained within our mmapped"
" file (%s) of length %zu",
static_cast<size_t>(offset), static_cast<size_t>(offset),
" + ",
sizeof(T), sizeof(T),
") is not contained within our mapped file (",
filepath_, filepath_,
") of length ",
length_); length_);
FOLLY_SAFE_CHECK(offset + sizeof(T) <= length_, msg);
}
return *reinterpret_cast<T*>(file_ + offset); return *reinterpret_cast<T*>(file_ + offset);
} }
......
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