DiD: Ensure string offsets are inside string boundaries

This commit is contained in:
Benny Baumann 2020-12-21 22:35:38 +01:00
parent 10c6810bff
commit 6502b02666
1 changed files with 6 additions and 0 deletions

View File

@ -376,6 +376,9 @@ void LinuxProcess_makeCommandStr(Process* this) {
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 */
if (strncmp(cmdline + cmdlineBasenameOffset, procComm, MINIMUM(TASK_COMM_LEN - 1, strlen(procComm))) != 0) {
@ -411,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);