Fix Coverity issues 41/214141/1
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 18 Sep 2019 09:34:49 +0000 (11:34 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 18 Sep 2019 09:39:06 +0000 (11:39 +0200)
Change-Id: I84d25d996c2134e141bb366ca3adc77743ba98ba

src/livedumper/core.hpp

index aebd3a4..bd1737c 100644 (file)
@@ -222,13 +222,18 @@ class Core {
        }
 
        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)" :
@@ -459,7 +464,7 @@ class Core {
                        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);
                        }