summaryrefslogtreecommitdiffstats
path: root/linker
diff options
context:
space:
mode:
authorDmitriy Ivanov <dimitry@google.com>2014-10-21 12:09:18 -0700
committerDmitriy Ivanov <dimitry@google.com>2014-10-22 16:35:04 +0000
commit702ab5b37e77684ee352300d32b078606ee388d0 (patch)
treecf004ce39ae961ab9261e1622acc2a773e47a8e6 /linker
parent3c5c720b0b46ecd801329c09d23bb6e7098d76d3 (diff)
downloadbionic-702ab5b37e77684ee352300d32b078606ee388d0.zip
bionic-702ab5b37e77684ee352300d32b078606ee388d0.tar.gz
bionic-702ab5b37e77684ee352300d32b078606ee388d0.tar.bz2
Rename library_offset to library_fd_offset
replace lseek() and use pread() instead add test for library_fd_offset > file_size case Bug: 17762003 (cherry picked from commit a6c1279098f24a675d0df74ce1946f5d534b425e) Change-Id: Ie117c745081ee33d07db5341115ff6c8e98b0dec
Diffstat (limited to 'linker')
-rw-r--r--linker/linker.cpp12
-rw-r--r--linker/linker_phdr.cpp10
2 files changed, 8 insertions, 14 deletions
diff --git a/linker/linker.cpp b/linker/linker.cpp
index d6d5f35..9425c9d 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -817,8 +817,8 @@ static soinfo* load_library(LoadTaskList& load_tasks, const char* name, int dlfl
if (extinfo != nullptr && (extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD) != 0) {
fd = extinfo->library_fd;
- if ((extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_OFFSET) != 0) {
- file_offset = extinfo->library_offset;
+ if ((extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET) != 0) {
+ file_offset = extinfo->library_fd_offset;
}
} else {
// Open the file.
@@ -832,13 +832,13 @@ static soinfo* load_library(LoadTaskList& load_tasks, const char* name, int dlfl
}
if ((file_offset % PAGE_SIZE) != 0) {
- DL_ERR("file offset for the library %s is not page-aligned: %" PRId64, name, file_offset);
+ DL_ERR("file offset for the library \"%s\" is not page-aligned: %" PRId64, name, file_offset);
return nullptr;
}
struct stat file_stat;
if (TEMP_FAILURE_RETRY(fstat(fd, &file_stat)) != 0) {
- DL_ERR("unable to stat file for the library %s: %s", name, strerror(errno));
+ DL_ERR("unable to stat file for the library \"%s\": %s", name, strerror(errno));
return nullptr;
}
@@ -1085,8 +1085,8 @@ soinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo)
return nullptr;
}
if ((extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD) == 0 &&
- (extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_OFFSET) != 0) {
- DL_ERR("invalid extended flag combination (ANDROID_DLEXT_USE_LIBRARY_OFFSET without ANDROID_DLEXT_USE_LIBRARY_FD): 0x%" PRIx64, extinfo->flags);
+ (extinfo->flags & ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET) != 0) {
+ DL_ERR("invalid extended flag combination (ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET without ANDROID_DLEXT_USE_LIBRARY_FD): 0x%" PRIx64, extinfo->flags);
return nullptr;
}
}
diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp
index e0d6d0e..4b1c0ca 100644
--- a/linker/linker_phdr.cpp
+++ b/linker/linker_phdr.cpp
@@ -142,18 +142,12 @@ bool ElfReader::Load(const android_dlextinfo* extinfo) {
}
bool ElfReader::ReadElfHeader() {
- off64_t actual_offset = lseek64(fd_, file_offset_, SEEK_SET);
-
- if (actual_offset != file_offset_) {
- DL_ERR("seek to %" PRId64 " failed: %s", file_offset_, strerror(errno));
- return false;
- }
-
- ssize_t rc = TEMP_FAILURE_RETRY(read(fd_, &header_, sizeof(header_)));
+ ssize_t rc = TEMP_FAILURE_RETRY(pread64(fd_, &header_, sizeof(header_), file_offset_));
if (rc < 0) {
DL_ERR("can't read file \"%s\": %s", name_, strerror(errno));
return false;
}
+
if (rc != sizeof(header_)) {
DL_ERR("\"%s\" is too small to be an ELF executable: only found %zd bytes", name_,
static_cast<size_t>(rc));