Skip to content

Commit 9f8e5ae

Browse files
committed
tracing: Fix allocation of last_cmd in last_cmd_set()
The strncat() used in last_cmd_set() includes the nul byte of length of the string being copied in, when it should only hold the size of the string being copied (not the nul byte). Change it to subtract the length of the allocated space and the nul byte to pass that into the strncat(). Also, assign "len" instead of initializing it to zero and its first update is to do a "+=". Link: https://lore.kernel.org/all/202202140628.fj6e4w4v-lkp@intel.com/ Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 864ea0e commit 9f8e5ae

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

kernel/trace/trace_events_hist.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,19 +744,20 @@ static void last_cmd_set(struct trace_event_file *file, char *str)
744744
{
745745
const char *system = NULL, *name = NULL;
746746
struct trace_event_call *call;
747-
int len = 0;
747+
int len;
748748

749749
if (!str)
750750
return;
751751

752-
len += sizeof(HIST_PREFIX) + strlen(str) + 1;
752+
len = sizeof(HIST_PREFIX) + strlen(str) + 1;
753753
kfree(last_cmd);
754754
last_cmd = kzalloc(len, GFP_KERNEL);
755755
if (!last_cmd)
756756
return;
757757

758758
strcpy(last_cmd, HIST_PREFIX);
759-
strncat(last_cmd, str, len - sizeof(HIST_PREFIX));
759+
len -= sizeof(HIST_PREFIX) + 1;
760+
strncat(last_cmd, str, len);
760761

761762
if (file) {
762763
call = file->event_call;

0 commit comments

Comments
 (0)