Avoid NULL dereference on zombie processes

Fixes #361
This commit is contained in:
Benny Baumann 2020-12-21 22:29:18 +01:00
parent 068561351f
commit 10c6810bff
1 changed files with 9 additions and 2 deletions

View File

@ -368,6 +368,13 @@ void LinuxProcess_makeCommandStr(Process* this) {
char *str = strStart; char *str = strStart;
int cmdlineBasenameOffset = lp->procCmdlineBasenameOffset; int cmdlineBasenameOffset = lp->procCmdlineBasenameOffset;
int cmdlineBasenameEnd = lp->procCmdlineBasenameEnd;
if (!cmdline) {
cmdlineBasenameOffset = 0;
cmdlineBasenameEnd = 0;
cmdline = "(zombie)";
}
if (!showMergedCommand || !procExe || !procComm) { /* fall back to cmdline */ if (!showMergedCommand || !procExe || !procComm) { /* fall back to cmdline */
if (showMergedCommand && !procExe && procComm && strlen(procComm)) { /* Prefix column with comm */ if (showMergedCommand && !procExe && procComm && strlen(procComm)) { /* Prefix column with comm */
@ -385,11 +392,11 @@ void LinuxProcess_makeCommandStr(Process* this) {
if (showProgramPath) { if (showProgramPath) {
(void) stpcpyWithNewlineConversion(str, cmdline); (void) stpcpyWithNewlineConversion(str, cmdline);
mc->baseStart = cmdlineBasenameOffset; mc->baseStart = cmdlineBasenameOffset;
mc->baseEnd = lp->procCmdlineBasenameEnd; mc->baseEnd = cmdlineBasenameEnd;
} else { } else {
(void) stpcpyWithNewlineConversion(str, cmdline + cmdlineBasenameOffset); (void) stpcpyWithNewlineConversion(str, cmdline + cmdlineBasenameOffset);
mc->baseStart = 0; mc->baseStart = 0;
mc->baseEnd = lp->procCmdlineBasenameEnd - cmdlineBasenameOffset; mc->baseEnd = cmdlineBasenameEnd - cmdlineBasenameOffset;
} }
if (mc->sep1) { if (mc->sep1) {