# Re: \[PATCH\] tracing: Replace strncpy() with strscpy() when copying comm

- From: Steven Rostedt \<rostedt@goodmis.org\>
- Date: 2024-10-30 23:40:09 
- List: linux-trace-kernel
- Page: https://ratatoskr.run/linux-trace-kernel/2024/10/2806754
- Thread: https://ratatoskr.run/linux-trace-kernel/2024/07/2690619/t.md

```text
On Wed, 31 Jul 2024 15:50:58 +0800
Jinjie Ruan [ref] wrote:

> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index 6ece1308d36a..4ee0e64719fa 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
> @@ -1599,7 +1599,7 @@ static inline void save_comm(char *comm, struct task_struct *task)
>  		return;
>  	}
>  
> -	strncpy(comm, task->comm, TASK_COMM_LEN);
> +	strscpy(comm, task->comm);
>  }
>  

Was this even compiled?

In file included from /work/git/test-linux.git/include/linux/container_of.h:5,
                 from /work/git/test-linux.git/include/linux/list.h:5,
                 from /work/git/test-linux.git/include/linux/module.h:12,
                 from /work/git/test-linux.git/kernel/trace/trace_events_hist.c:8:
/work/git/test-linux.git/kernel/trace/trace_events_hist.c: In function ‘save_comm’:
/work/git/test-linux.git/include/linux/build_bug.h:16:51: error: negative width in bit-field ‘<anonymous>’
   16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
      |                                                   ^
/work/git/test-linux.git/include/linux/compiler.h:243:33: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’
  243 | #define __must_be_array(a)      BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
      |                                 ^~~~~~~~~~~~~~~~~
/work/git/test-linux.git/include/linux/string.h:79:47: note: in expansion of macro ‘__must_be_array’
   79 |         sized_strscpy(dst, src, sizeof(dst) + __must_be_array(dst) +    \
      |                                               ^~~~~~~~~~~~~~~
/work/git/test-linux.git/include/linux/args.h:25:24: note: in expansion of macro ‘__strscpy0’
   25 | #define __CONCAT(a, b) a ## b
      |                        ^
/work/git/test-linux.git/include/linux/args.h:26:27: note: in expansion of macro ‘__CONCAT’
   26 | #define CONCATENATE(a, b) __CONCAT(a, b)
      |                           ^~~~~~~~
/work/git/test-linux.git/include/linux/string.h:113:9: note: in expansion of macro ‘CONCATENATE’
  113 |         CONCATENATE(__strscpy, COUNT_ARGS(__VA_ARGS__))(dst, src, __VA_ARGS__)
      |         ^~~~~~~~~~~
/work/git/test-linux.git/kernel/trace/trace_events_hist.c:1602:9: note: in expansion of macro ‘strscpy’
 1602 |         strscpy(comm, task->comm);
      |         ^~~~~~~

Bah!

-- Steve
```
