From 4af8c63f63648a89574abdc1f8638ada2e49cfae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Tue, 24 Nov 2020 19:54:25 +0100 Subject: Fix file descriptor leak in LinuxProcessList_readCmdlineFile after xread failure Found by Coverity --- linux/LinuxProcessList.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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) { -- cgit v1.2.3