0007-pgrep: Always null-terminate the cmd*[] buffers.
Otherwise, man strncpy: "If there is no null byte among the first n bytes of src, the string placed in dest will not be null-terminated."
This commit is contained in:
parent
8e6d11a928
commit
df0e1a13ab
10
pgrep.c
10
pgrep.c
@ -549,16 +549,18 @@ static struct el * select_procs (int *num)
|
||||
|
||||
if (opt_long || opt_longlong || (match && opt_pattern)) {
|
||||
if (opt_longlong)
|
||||
strncpy (cmdoutput, task_cmdline, CMDSTRSIZE-1);
|
||||
strncpy (cmdoutput, task_cmdline, sizeof cmdoutput -1);
|
||||
else
|
||||
strncpy (cmdoutput, PIDS_GETSTR(CMD), CMDSTRSIZE-1);
|
||||
strncpy (cmdoutput, PIDS_GETSTR(CMD), sizeof cmdoutput -1);
|
||||
cmdoutput[sizeof cmdoutput - 1] = '\0';
|
||||
}
|
||||
|
||||
if (match && opt_pattern) {
|
||||
if (opt_full)
|
||||
strncpy (cmdsearch, task_cmdline, CMDSTRSIZE-1);
|
||||
strncpy (cmdsearch, task_cmdline, sizeof cmdsearch -1);
|
||||
else
|
||||
strncpy (cmdsearch, PIDS_GETSTR(CMD), CMDSTRSIZE-1);
|
||||
strncpy (cmdsearch, PIDS_GETSTR(CMD), sizeof cmdsearch -1);
|
||||
cmdsearch[sizeof cmdsearch - 1] = '\0';
|
||||
|
||||
if (regexec (preg, cmdsearch, 0, NULL, 0) != 0)
|
||||
match = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user