From: VMware, Inc <> Date: Mon, 26 Sep 2011 18:56:37 +0000 (-0700) Subject: VixTools: List Processes - Fix for potential core and couple of optimizations. X-Git-Tag: 2011.09.23-491607~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=28afee7070544af2c48847072f306f3b20aa122f;p=thirdparty%2Fopen-vm-tools.git VixTools: List Processes - Fix for potential core and couple of optimizations. 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 --- diff --git a/open-vm-tools/services/plugins/vix/vixTools.c b/open-vm-tools/services/plugins/vix/vixTools.c index 8f30d4e95..be7e2ff03 100644 --- a/open-vm-tools/services/plugins/vix/vixTools.c +++ b/open-vm-tools/services/plugins/vix/vixTools.c @@ -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;