projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix some copyright lines in folly/experimental/symbolizer/
[folly.git]
/
folly
/
experimental
/
symbolizer
/
Elf.cpp
diff --git
a/folly/experimental/symbolizer/Elf.cpp
b/folly/experimental/symbolizer/Elf.cpp
index 071f1b43ea83ceb3f2adfef2f269b55beb52f219..2ff63863126d517a7a2351f053117402ccaef663 100644
(file)
--- a/
folly/experimental/symbolizer/Elf.cpp
+++ b/
folly/experimental/symbolizer/Elf.cpp
@@
-20,6
+20,7
@@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <cstring>
#include <string>
#include <glog/logging.h>
#include <string>
#include <glog/logging.h>
@@
-64,6
+65,7
@@
int ElfFile::openNoThrow(
bool readOnly,
const char** msg) noexcept {
FOLLY_SAFE_CHECK(fd_ == -1, "File already open");
bool readOnly,
const char** msg) noexcept {
FOLLY_SAFE_CHECK(fd_ == -1, "File already open");
+ strncat(filepath_, name, kFilepathMaxLen - 1);
fd_ = ::open(name, readOnly ? O_RDONLY : O_RDWR);
if (fd_ == -1) {
if (msg) {
fd_ = ::open(name, readOnly ? O_RDONLY : O_RDWR);
if (fd_ == -1) {
if (msg) {
@@
-157,6
+159,9
@@
ElfFile::ElfFile(ElfFile&& other) noexcept
file_(other.file_),
length_(other.length_),
baseAddress_(other.baseAddress_) {
file_(other.file_),
length_(other.length_),
baseAddress_(other.baseAddress_) {
+ // copy other.filepath_, leaving filepath_ zero-terminated, always.
+ strncat(filepath_, other.filepath_, kFilepathMaxLen - 1);
+ other.filepath_[0] = 0;
other.fd_ = -1;
other.file_ = static_cast<char*>(MAP_FAILED);
other.length_ = 0;
other.fd_ = -1;
other.file_ = static_cast<char*>(MAP_FAILED);
other.length_ = 0;
@@
-167,11
+172,14
@@
ElfFile& ElfFile::operator=(ElfFile&& other) {
assert(this != &other);
reset();
assert(this != &other);
reset();
+ // copy other.filepath_, leaving filepath_ zero-terminated, always.
+ strncat(filepath_, other.filepath_, kFilepathMaxLen - 1);
fd_ = other.fd_;
file_ = other.file_;
length_ = other.length_;
baseAddress_ = other.baseAddress_;
fd_ = other.fd_;
file_ = other.file_;
length_ = other.length_;
baseAddress_ = other.baseAddress_;
+ other.filepath_[0] = 0;
other.fd_ = -1;
other.file_ = static_cast<char*>(MAP_FAILED);
other.length_ = 0;
other.fd_ = -1;
other.file_ = static_cast<char*>(MAP_FAILED);
other.length_ = 0;
@@
-181,6
+189,8
@@
ElfFile& ElfFile::operator=(ElfFile&& other) {
}
void ElfFile::reset() {
}
void ElfFile::reset() {
+ filepath_[0] = 0;
+
if (file_ != MAP_FAILED) {
munmap(file_, length_);
file_ = static_cast<char*>(MAP_FAILED);
if (file_ != MAP_FAILED) {
munmap(file_, length_);
file_ = static_cast<char*>(MAP_FAILED);
@@
-193,19
+203,24
@@
void ElfFile::reset() {
}
bool ElfFile::init(const char** msg) {
}
bool ElfFile::init(const char** msg) {
- auto& elfHeader = this->elfHeader();
+ if (length_ < 4) {
+ if (msg) {
+ *msg = "not an ELF file (too short)";
+ }
+ return false;
+ }
// Validate ELF magic numbers
// Validate ELF magic numbers
- if (!(elfHeader.e_ident[EI_MAG0] == ELFMAG0 &&
- elfHeader.e_ident[EI_MAG1] == ELFMAG1 &&
- elfHeader.e_ident[EI_MAG2] == ELFMAG2 &&
- elfHeader.e_ident[EI_MAG3] == ELFMAG3)) {
+ if (file_[EI_MAG0] != ELFMAG0 || file_[EI_MAG1] != ELFMAG1 ||
+ file_[EI_MAG2] != ELFMAG2 || file_[EI_MAG3] != ELFMAG3) {
if (msg) {
*msg = "invalid ELF magic";
}
return false;
}
if (msg) {
*msg = "invalid ELF magic";
}
return false;
}
+ auto& elfHeader = this->elfHeader();
+
#define EXPECTED_CLASS P1(ELFCLASS, __ELF_NATIVE_CLASS)
#define P1(a, b) P2(a, b)
#define P2(a, b) a##b
#define EXPECTED_CLASS P1(ELFCLASS, __ELF_NATIVE_CLASS)
#define P1(a, b) P2(a, b)
#define P2(a, b) a##b