On Fri, Sep 07, 2018 at 06:08:56AM -0400, Prarit Bhargava wrote:
> gcc 8.1.0 warns with:
> 
> kernel/debug/kdb/kdb_support.c: In function ‘kallsyms_symbol_next’:
> kernel/debug/kdb/kdb_support.c:239:4: warning: ‘strncpy’ specified bound 
> depends on the length of the source argument [-Wstringop-overflow=]
>     strncpy(prefix_name, name, strlen(name)+1);
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> kernel/debug/kdb/kdb_support.c:239:31: note: length computed here
> 
> The strings do not need to be zero padded so use strlcpy() instead.
> 
> Signed-off-by: Prarit Bhargava <pra...@redhat.com>
> Cc: Jonathan Toppins <jtopp...@redhat.com>
> Cc: Jason Wessel <jason.wes...@windriver.com>
> Cc: Daniel Thompson <daniel.thomp...@linaro.org>
> ---
>  kernel/debug/kdb/kdb_support.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c
> index 990b3cc526c8..1ad4370ccbf0 100644
> --- a/kernel/debug/kdb/kdb_support.c
> +++ b/kernel/debug/kdb/kdb_support.c
> @@ -236,7 +236,7 @@ int kallsyms_symbol_next(char *prefix_name, int flag)
>  
>       while ((name = kdb_walk_kallsyms(&pos))) {
>               if (strncmp(name, prefix_name, prefix_len) == 0) {
> -                     strncpy(prefix_name, name, strlen(name)+1);
> +                     strlcpy(prefix_name, name, strlen(name)+1);

How does this *fix* the warning?

The warning occurs because a "safe" string copy function is incorrectly
using the length of the second argument as the length (i.e. it is simply
an inefficient implementation of strcpy). The code is still bogus
whether you use strncpy, strlcpy or strscpy. All we are doing here is
kicking the ball down the road until someone teaches gcc 9+ about
strlcpy()!


Daniel.


_______________________________________________
Kgdb-bugreport mailing list
Kgdb-bugreport@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kgdb-bugreport

Reply via email to