summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-11-24 19:54:25 +0100
committerChristian Göttsche <cgzones@googlemail.com>2020-11-24 19:54:25 +0100
commit4af8c63f63648a89574abdc1f8638ada2e49cfae (patch)
tree32a0934a58394cc7deb563049b012cac6cf6fc99
parent21e3063e2edec4f7cbcf9188aa85ac20cd082939 (diff)
Fix file descriptor leak in LinuxProcessList_readCmdlineFile after xread failure
Found by Coverity
-rw-r--r--linux/LinuxProcessList.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index 4c6a8f23..1b075630 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -1023,7 +1023,6 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
xSnprintf(filename, MAX_NAME, "%s/%s/comm", dirname, name);
if ((fd = open(filename, O_RDONLY)) != -1 &&
(amtRead = xread(fd, command, sizeof(command) - 1)) > 0) {
- close(fd);
command[amtRead - 1] = 0;
lp->mergedCommand.maxLen += amtRead - 1; /* accomodate comm */
if (!lp->procComm || strcmp(command, lp->procComm)) {
@@ -1037,6 +1036,9 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna
lp->mergedCommand.commChanged = true;
}
+ if (fd != -1)
+ close(fd);
+
/* execve could change /proc/[pid]/exe, so procExe should be udpated */
xSnprintf(command, sizeof(command), "%s/%s/exe", dirname, name);
if ((amtRead = readlink(command, filename, sizeof(filename) - 1)) > 0) {

© 2014-2024 Faster IT GmbH | imprint | privacy policy