From bd5d37f297fed2a42acbbd730e2af5ad45af6afa Mon Sep 17 00:00:00 2001 From: Hisham Date: Wed, 24 Aug 2016 18:11:10 -0300 Subject: Return when reading cmdline fails (e.g. zombie process) --- linux/LinuxProcessList.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'linux/LinuxProcessList.c') diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 712baa51..20e3d58c 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -471,23 +471,25 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna close(fd); int tokenEnd = 0; int lastChar = 0; - if (amtRead > 0) { - for (int i = 0; i < amtRead; i++) - if (command[i] == '\0' || command[i] == '\n') { - if (tokenEnd == 0) { - tokenEnd = i; - } - command[i] = ' '; - } else { - lastChar = i; + if (amtRead <= 0) { + return false; + } + for (int i = 0; i < amtRead; i++) { + if (command[i] == '\0' || command[i] == '\n') { + if (tokenEnd == 0) { + tokenEnd = i; } + command[i] = ' '; + } else { + lastChar = i; + } } if (tokenEnd == 0) { tokenEnd = amtRead; } command[lastChar + 1] = '\0'; process->basenameOffset = tokenEnd; - setCommand(process, command, lastChar + 1); + setCommand(process, command, lastChar); return true; } -- cgit v1.2.3