From: Oliver Kurth Date: Wed, 3 Jul 2019 21:28:56 +0000 (-0700) Subject: Fix the command name for few linux processes. X-Git-Tag: stable-11.0.0~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2660d40ca4f5beca0ba3a4c68a66f8c7dcf77a67;p=thirdparty%2Fopen-vm-tools.git Fix the command name for few linux processes. ProcMgr library publishes the 'command name' attribute for each process while listing down all the processes. For doing this, the commandline is first parsed from /proc//cmdline file and the part starting from the right-most '/' is considered as the command name. This is OK only if we have an absolute path for the command binary. Other wise, this may result in incorrect results. For example: sshd: root@pts/1 gdm-session-worker [pam/gdm-autologin] Fixed the code to ignore the parsing if we do not have an absolute path. Note: There are two ways how the command name is retrieved for each process. 1. /proc//cmdline is parsed. If (1) fails for some reason, then 2. /proc//status is parsed. There is no issue with (2). This changeset fixes the parsing issue only with (1) approach mentioned above. --- diff --git a/open-vm-tools/lib/procMgr/procMgrPosix.c b/open-vm-tools/lib/procMgr/procMgrPosix.c index 2f7711bdb..e38a6dbf6 100644 --- a/open-vm-tools/lib/procMgr/procMgrPosix.c +++ b/open-vm-tools/lib/procMgr/procMgrPosix.c @@ -340,7 +340,6 @@ ProcMgr_ListProcesses(void) unsigned long long dummy; unsigned long long relativeStartTime; char *stringBegin; - char *cmdNameBegin; Bool cmdNameLookup = TRUE; /* @@ -410,15 +409,22 @@ ProcMgr_ListProcesses(void) * Store the command name. * Find the last path separator, to get the cmd name. * If no separator is found, then use the whole name. + * This needs to be done only if there is an absolute + * path for the binary. Else, the parsing may result + * in incorrect results. Following are few examples: + * + * sshd: root@pts/1 + * gdm-session-worker [pam/gdm-autologin] + * */ - cmdNameBegin = strrchr(cmdLineTemp, '/'); - if (NULL == cmdNameBegin) { - cmdNameBegin = cmdLineTemp; - } else { + char *cmdNameBegin = strrchr(cmdLineTemp, '/'); + if (NULL != cmdNameBegin && cmdLineTemp[0] == '/') { /* * Skip over the last separator. */ cmdNameBegin++; + } else { + cmdNameBegin = cmdLineTemp; } procInfo.procCmdName = Unicode_Alloc(cmdNameBegin, STRING_ENCODING_DEFAULT); if (procInfo.procCmdAbsPath != NULL &&