While listing down the processes in a linux guest, the existing
procMgr library reads /proc/<PID>/cmdline file and parses the
content. While reading this, an assumption is made that there is
a null terminating character at the end of the file content.
This holds true for most of the processes. But for few special processes,
the cmdline file doesn't have the terminating null character.
Proper content from cmdline file:
/usr/lib/systemd/systemd\0--switched-root\0--system\0--deserialize\021\0
/usr/sbin/vmtoolsd\0
sshd: root@pts/2\0\0\0
Example cmdline file where NUL terminator is missing:
avahi-daemon: running [linux.local]
avahi-daemon: chroot helper
if (numRead > 0) {
for (replaceLoop = 0 ; replaceLoop < numRead ; replaceLoop++) {
- if ('\0' == cmdLineTemp[replaceLoop]) {
+ if ('\0' == cmdLineTemp[replaceLoop] ||
+ replaceLoop == numRead - 1) {
if (cmdNameLookup) {
/*
* Store the command name.