]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
VixTools: List Processes - Fix for potential core and couple of optimizations.
authorVMware, Inc <>
Mon, 26 Sep 2011 18:56:37 +0000 (11:56 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Mon, 26 Sep 2011 18:56:37 +0000 (11:56 -0700)
Change 1: Once we have found and printed the input pid we are looking for,
we can "break" the loop and move to the next input pid.

Change 2: The ignore for exited pid belongs to the outer "for" loop.

Change 3: Incorrect indexing into procList prints wrong process info. Also
may cause a core if "i >= procList->procCount".

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/services/plugins/vix/vixTools.c

index 8f30d4e954fdf6aec81ef78f1ea785ef435f6dc1..be7e2ff0334c1888fd8b2fbf08292e4bde7208f1 100644 (file)
@@ -4562,6 +4562,7 @@ VixToolsListProcessesExGenerateData(uint32 numPids,          // IN
                if (VIX_OK != err) {
                   goto abort;
                }
+               break;
             }
             epList = epList->next;
          }
@@ -4592,20 +4593,20 @@ VixToolsListProcessesExGenerateData(uint32 numPids,          // IN
     */
    if (numPids > 0) {
       for (i = 0; i < numPids; i++) {
+         // ignore it if its on the exited list -- we added it above
+         if (VixToolsFindExitedProgramState(pids[i])) {
+            continue;
+         }
          for (j = 0; j < procList->procCount; j++) {
-            // ignore it if its on the exited list -- we added it above
-            if (VixToolsFindExitedProgramState(pids[i])) {
-               continue;
-            }
             if (pids[i] == procList->procIdList[j]) {
                err = VixToolsPrintProcInfoEx(&dynBuffer,
-                                             procList->procCmdList[i],
-                                             procList->procIdList[i],
+                                             procList->procCmdList[j],
+                                             procList->procIdList[j],
                                              (NULL == procList->procOwnerList
-                                              || NULL == procList->procOwnerList[i])
-                                             ? "" : procList->procOwnerList[i],
+                                              || NULL == procList->procOwnerList[j])
+                                             ? "" : procList->procOwnerList[j],
                                              (NULL == procList->startTime)
-                                             ? 0 : (int) procList->startTime[i],
+                                             ? 0 : (int) procList->startTime[j],
                                              0, 0);
                if (VIX_OK != err) {
                   goto abort;