From: Oliver Kurth Date: Wed, 8 May 2019 22:27:20 +0000 (-0700) Subject: Fix the 'procCmdName' attribute of process information. X-Git-Tag: stable-11.0.0~80 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b0e339cde98dce03ec5046c04ded329f61dc5ef;p=thirdparty%2Fopen-vm-tools.git Fix the 'procCmdName' attribute of process information. * When listing down the processes, /proc/{PID}/cmdline file is read and parsed to figure out the command name. While doing this parsing, the terminating NUL character is not parsed. Due to this, if any process doesn't have any command line arguments, the 'command name' is retrieved as NULL. Note: This issue doesn't happen if the cmdLine has any arguments. Ex: /usr/bin/vmtoolsd -> 'cmdName' is retrieved as NULL /usr/bin/vmtoolsd -n vmusr -> 'cmdName' is retrieved properly as 'vmtoolsd' * Fixed the code to include the trailing NUL character also while parsing. --- diff --git a/open-vm-tools/lib/procMgr/procMgrPosix.c b/open-vm-tools/lib/procMgr/procMgrPosix.c index e492f9a96..97c995900 100644 --- a/open-vm-tools/lib/procMgr/procMgrPosix.c +++ b/open-vm-tools/lib/procMgr/procMgrPosix.c @@ -387,10 +387,7 @@ ProcMgr_ListProcesses(void) } if (numRead > 0) { - /* - * Stop before we hit the final '\0'; want to leave it alone. - */ - for (replaceLoop = 0 ; replaceLoop < (numRead - 1) ; replaceLoop++) { + for (replaceLoop = 0 ; replaceLoop < numRead ; replaceLoop++) { if ('\0' == cmdLineTemp[replaceLoop]) { if (cmdNameLookup) { /* @@ -410,7 +407,16 @@ ProcMgr_ListProcesses(void) procInfo.procCmdName = Unicode_Alloc(cmdNameBegin, STRING_ENCODING_DEFAULT); cmdNameLookup = FALSE; } - cmdLineTemp[replaceLoop] = ' '; + + /* + * In /proc/{PID}/cmdline file, the command and the + * arguments are separated by '\0'. We need to replace + * only the intermediate '\0' with ' ' and not the trailing + * NUL characer. + */ + if (replaceLoop < (numRead - 1)) { + cmdLineTemp[replaceLoop] = ' '; + } } } } else {