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 {
template <class T>
const T& at(ElfOff offset) const noexcept {
static_assert(std::is_pod<T>::value, "non-pod");
if (offset + sizeof(T) > length_) {
char msg[kFilepathMaxLen + 128];
snprintf(
msg,
sizeof(msg),
"Offset (%zu + %zu) is not contained within our mmapped"
" file (%s) of length %zu",
static_cast<size_t>(offset),
sizeof(T),
filepath_,
length_);
FOLLY_SAFE_CHECK(offset + sizeof(T) <= length_, msg);
}
FOLLY_SAFE_CHECK(
offset + sizeof(T) <= length_,
"Offset (",
static_cast<size_t>(offset),
" + ",
sizeof(T),
") is not contained within our mapped file (",
filepath_,
") of length ",
length_);
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