}
void ReadFromFile(const int fd, unsigned long address, void *data, size_t len) {
- lseek64(fd, address, SEEK_SET);
+ if (lseek64(fd, address, SEEK_SET) == -1)
+ throw std::system_error(errno, std::system_category(), "failed to lseek64 at " + std::to_string(address));
if (read(fd, data, len) == -1)
throw std::system_error(errno, std::system_category(), "failed to read at " + std::to_string(address));
}
void DumpData(int fd, std::ofstream &output, typename T::Addr iaddress, typename T::Addr oaddress, size_t len, const std::string &desc) {
- lseek64(fd, iaddress, SEEK_SET);
+ if (lseek64(fd, iaddress, SEEK_SET) == -1) {
+ logger.log_info("failed to lseek64");
+ return;
+ }
+
output.seekp(oaddress, std::ios_base::beg);
constexpr const char * format = std::is_same<T, Elf64>::value ?
"dumping %s: 0x%" PRIx64 "-0x%" PRIx64 " to 0x%" PRIx64 " (%zu bytes)" :
ReadFromFile(mem_fd, addr, buff, sizeof(buff));
if (buff[0] != 0) {
- DumpData(mem_fd, core_file, addr, strlen(buff) + 1, "l_name");
+ DumpData(mem_fd, core_file, addr, strnlen(buff, sizeof(buff)) + 1, "l_name");
ReadFromFile(mem_fd, ptr+offsetof(struct link_map, l_addr), &addr, sizeof(addr));
SaveSymData(buff, addr);
}