Fix assert failure on short running thread

The following assert failure might happen on short running threads with
an empty comm value in /proc/${pid}/stat:

htop: Process.c:1159: void Process_updateCmdline(Process *, const char *, int, int): Assertion `(cmdline && basenameStart < (int)strlen(cmdline)) || (!cmdline && basenameStart == 0)' failed.

The specific task is:
    comm=''
    exe='(null)'
    cmdline='/usr/bin/ruby /usr/bin/how-can-i-help --apt'

So basenameStart is 0, while strlen(cmdline) is also 0.
This commit is contained in:
Christian Göttsche 2021-05-23 15:21:51 +02:00
parent 771a1be316
commit 3d5b6d9282
1 changed files with 6 additions and 6 deletions

View File

@ -1351,10 +1351,10 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
} }
} }
char command[MAX_NAME + 1]; char statCommand[MAX_NAME + 1];
unsigned long long int lasttimes = (lp->utime + lp->stime); unsigned long long int lasttimes = (lp->utime + lp->stime);
unsigned long int tty_nr = proc->tty_nr; unsigned long int tty_nr = proc->tty_nr;
if (! LinuxProcessList_readStatFile(proc, procFd, command, sizeof(command))) if (! LinuxProcessList_readStatFile(proc, procFd, statCommand, sizeof(statCommand)))
goto errorReadingProcess; goto errorReadingProcess;
if (tty_nr != proc->tty_nr && this->ttyDrivers) { if (tty_nr != proc->tty_nr && this->ttyDrivers) {
@ -1431,11 +1431,11 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_
LinuxProcessList_readCwd(lp, procFd); LinuxProcessList_readCwd(lp, procFd);
} }
if (proc->state == 'Z' && !proc->cmdline) { if (proc->state == 'Z' && !proc->cmdline && statCommand[0]) {
Process_updateCmdline(proc, command, 0, 0); Process_updateCmdline(proc, statCommand, 0, strlen(statCommand));
} else if (Process_isThread(proc)) { } else if (Process_isThread(proc)) {
if (settings->showThreadNames || Process_isKernelThread(proc)) { if ((settings->showThreadNames || Process_isKernelThread(proc)) && statCommand[0]) {
Process_updateCmdline(proc, command, 0, 0); Process_updateCmdline(proc, statCommand, 0, strlen(statCommand));
} }
if (Process_isKernelThread(proc)) { if (Process_isKernelThread(proc)) {