lkml.org 
[lkml]   [2020]   [Jun]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [PATCH] crypto: hisilicon - fix strncpy warning with strlcpy
    From
    Date


    On 2020/6/4 上午11:39, Herbert Xu wrote:
    > On Thu, Jun 04, 2020 at 11:32:04AM +0800, Zhangfei Gao wrote:
    >> Use strlcpy to fix the warning
    >> warning: 'strncpy' specified bound 64 equals destination size
    >> [-Wstringop-truncation]
    >>
    >> Reported-by: kernel test robot <lkp@intel.com>
    >> Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
    >> ---
    >> drivers/crypto/hisilicon/qm.c | 2 +-
    >> 1 file changed, 1 insertion(+), 1 deletion(-)
    >>
    >> diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
    >> index f795fb5..224f3e2 100644
    >> --- a/drivers/crypto/hisilicon/qm.c
    >> +++ b/drivers/crypto/hisilicon/qm.c
    >> @@ -1574,7 +1574,7 @@ static int qm_alloc_uacce(struct hisi_qm *qm)
    >> .ops = &uacce_qm_ops,
    >> };
    >>
    >> - strncpy(interface.name, pdev->driver->name, sizeof(interface.name));
    >> + strlcpy(interface.name, pdev->driver->name, sizeof(interface.name));
    > Should this even allow truncation? Perhaps it'd be better to fail
    > in case of an overrun?
    I think we do not need consider overrun, since it at most copy size-1
    bytes to dest.
    From the manual: strlcpy()
           This  function  is  similar  to  strncpy(), but it copies at
    most size-1 bytes to dest, always adds a terminating null
           byte,
    And simple tested with smaller SIZE of interface.name,  only SIZE-1 is
    copied, so it is safe.
    -#define UACCE_MAX_NAME_SIZE    64
    +#define UACCE_MAX_NAME_SIZE    4

    Thanks

    \
     
     \ /
      Last update: 2020-06-04 08:11    [W:2.832 / U:0.020 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site