From: Michal Bloch Date: Mon, 8 Jul 2019 14:49:34 +0000 (+0200) Subject: Fix a bunch of minor issues found by Coverity. X-Git-Tag: submit/tizen/20190709.135841~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F209642%2F1;p=platform%2Fcore%2Fsystem%2Fcrash-worker.git Fix a bunch of minor issues found by Coverity. Change-Id: I6dc3f56f1d590a6a49800d28ba78d3185555a837 Signed-off-by: Michal Bloch --- diff --git a/src/livedumper/core.hpp b/src/livedumper/core.hpp index 193577c..2f52efd 100644 --- a/src/livedumper/core.hpp +++ b/src/livedumper/core.hpp @@ -136,6 +136,10 @@ class Core { len = size; ssize_t cur_pos = lseek64(input, 0, SEEK_CUR); + if (cur_pos < 0) { + logger.log_error("lseek error: %s", std::system_category().default_error_condition(errno).message()); + return; + } ssize_t bytes_read; if ((bytes_read = read(input, buff, len)) == -1) { diff --git a/src/livedumper/livedumper.hpp b/src/livedumper/livedumper.hpp index 6e0869a..01a2225 100644 --- a/src/livedumper/livedumper.hpp +++ b/src/livedumper/livedumper.hpp @@ -47,9 +47,15 @@ class LiveDumper { Core m_core; std::ofstream m_core_file; int prstatus_fd = -1; + std::pair map_buff; public: - explicit LiveDumper(const pid_t pid) : m_pid(pid) {} + explicit LiveDumper(const pid_t pid) : m_pid(pid), map_buff(MAP_FAILED, 0) {} + + ~ LiveDumper () { + if (map_buff.first != MAP_FAILED) + munmap(map_buff.first, map_buff.second); + } void CollectTpids() { m_tpids.clear(); @@ -148,14 +154,16 @@ class LiveDumper { memcpy(&prstatus.pr_reg, ®isters, sizeof(prstatus.pr_reg)); prstatus.pr_pid = m_pid; - auto buff = reinterpret_cast(mmap(nullptr, sizeof(prstatus), + map_buff.first = mmap(nullptr, sizeof(prstatus), PROT_READ | PROT_WRITE, MAP_SHARED, prstatus_fd, - 0)); - if (buff == MAP_FAILED) + 0); + if (map_buff.first == MAP_FAILED) return; - memcpy(buff, &prstatus, sizeof(prstatus)); + map_buff.second = sizeof prstatus; + + memcpy(static_cast (map_buff.first), &prstatus, sizeof(prstatus)); } void AddNotes(const std::vector> &records) { diff --git a/src/livedumper/program.hpp b/src/livedumper/program.hpp index 855e7e4..f2eca7d 100644 --- a/src/livedumper/program.hpp +++ b/src/livedumper/program.hpp @@ -30,6 +30,7 @@ class ProgramTableEntryBase { memset(&header, 0, sizeof(header)); header.p_type = p_type; } + virtual ~ProgramTableEntryBase () {} }; template diff --git a/src/shared/spawn.c b/src/shared/spawn.c index baca45d..392a053 100644 --- a/src/shared/spawn.c +++ b/src/shared/spawn.c @@ -51,6 +51,9 @@ int spawn_setstderr(spawn_param_s *param) int spawn_nullstdfds(spawn_param_s *param) { int fd = open("/dev/null", O_RDWR); + if (fd < 0) + return -1; + int ret = dup2(fd, STDIN_FILENO) < 0 || dup2(fd, STDOUT_FILENO) < 0 || dup2(fd, STDERR_FILENO) < 0 ? -1 : 0; if (fd != STDIN_FILENO && fd != STDOUT_FILENO && fd != STDERR_FILENO) close(fd);