]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix the 'procCmdName' attribute of process information.
authorOliver Kurth <okurth@vmware.com>
Wed, 8 May 2019 22:27:20 +0000 (15:27 -0700)
committerOliver Kurth <okurth@vmware.com>
Wed, 8 May 2019 22:27:20 +0000 (15:27 -0700)
* 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.

open-vm-tools/lib/procMgr/procMgrPosix.c

index e492f9a9626afb2f863e4b9b4e404d4ffa047b4e..97c995900f54ec4f545c94dc25386ca11569b1ef 100644 (file)
@@ -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 {