lkml.org 
[lkml]   [2020]   [Jun]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] crypto: hisilicon - fix strncpy warning with strlcpy
On Fri, Jun 05, 2020 at 11:26:20PM +0800, Zhangfei Gao wrote:
>
>
> On 2020/6/5 下午8:17, Herbert Xu wrote:
> > On Fri, Jun 05, 2020 at 05:34:32PM +0800, Zhangfei Gao wrote:
> > > Will add a check after the copy.
> > >
> > >         strlcpy(interface.name, pdev->driver->name, sizeof(interface.name));
> > >         if (strlen(pdev->driver->name) != strlen(interface.name))
> > >                 return -EINVAL;
> > You don't need to do strlen. The function strlcpy returns the
> > length of the source string.
> >
> > Better yet use strscpy which will even return an error for you.
> >
> >
> Yes, good idea, we can use strscpy.
>
> +       int ret;
>
> -       strncpy(interface.name, pdev->driver->name, sizeof(interface.name));
> +       ret = strscpy(interface.name, pdev->driver->name,
> sizeof(interface.name));
> +       if (ret < 0)
> +               return ret;

You might want to use -ENAMETOOLONG instead of the strscpy return value of
-E2BIG.

\
 
 \ /
  Last update: 2020-06-05 17:50    [W:0.418 / U:0.216 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site