* 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.
}
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) {
/*
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 {