Merge branch 'harden_makecommandstr' of https://github.com/BenBE/htop into BenBE-harden_makecommandstr

This commit is contained in:
Nathan Scott 2020-12-22 16:55:11 +11:00
commit fc7aead36b
1 changed files with 15 additions and 2 deletions

View File

@ -368,6 +368,16 @@ void LinuxProcess_makeCommandStr(Process* this) {
char *str = strStart;
int cmdlineBasenameOffset = lp->procCmdlineBasenameOffset;
int cmdlineBasenameEnd = lp->procCmdlineBasenameEnd;
if (!cmdline) {
cmdlineBasenameOffset = 0;
cmdlineBasenameEnd = 0;
cmdline = "(zombie)";
}
assert(cmdlineBasenameOffset >= 0);
assert(cmdlineBasenameOffset <= strlen(cmdline));
if (!showMergedCommand || !procExe || !procComm) { /* fall back to cmdline */
if (showMergedCommand && !procExe && procComm && strlen(procComm)) { /* Prefix column with comm */
@ -385,11 +395,11 @@ void LinuxProcess_makeCommandStr(Process* this) {
if (showProgramPath) {
(void) stpcpyWithNewlineConversion(str, cmdline);
mc->baseStart = cmdlineBasenameOffset;
mc->baseEnd = lp->procCmdlineBasenameEnd;
mc->baseEnd = cmdlineBasenameEnd;
} else {
(void) stpcpyWithNewlineConversion(str, cmdline + cmdlineBasenameOffset);
mc->baseStart = 0;
mc->baseEnd = lp->procCmdlineBasenameEnd - cmdlineBasenameOffset;
mc->baseEnd = cmdlineBasenameEnd - cmdlineBasenameOffset;
}
if (mc->sep1) {
@ -404,6 +414,9 @@ void LinuxProcess_makeCommandStr(Process* this) {
int exeBasenameOffset = lp->procExeBasenameOffset;
int exeBasenameLen = exeLen - exeBasenameOffset;
assert(exeBasenameOffset >= 0);
assert(exeBasenameOffset <= strlen(procExe));
/* Start with copying exe */
if (showProgramPath) {
str = stpcpy(str, procExe);