Re: [PATCH for-next 1/7] block/rnbd-clt: Get rid of warning regarding size argument in strlcpy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Dec 9, 2020 at 5:08 PM Bart Van Assche <bvanassche@xxxxxxx> wrote:
>
> On 12/9/20 12:20 AM, Jack Wang wrote:
> > From: Md Haris Iqbal <haris.iqbal@xxxxxxxxxxxxxxx>
> >
> > The kernel test robot triggerred the following warning,
> >
> >>> drivers/block/rnbd/rnbd-clt.c:1397:42: warning: size argument in
> > 'strlcpy' call appears to be size of the source; expected the size of the
> > destination [-Wstrlcpy-strlcat-size]
> >       strlcpy(dev->pathname, pathname, strlen(pathname) + 1);
> >                                             ~~~~~~~^~~~~~~~~~~~~
> >
> > To get rid of the above warning, use a len variable for doing kzalloc and
> > then strlcpy.
> >
> > Fixes: 64e8a6ece1a5 ("block/rnbd-clt: Dynamically alloc buffer for pathname & blk_symlink_name")
> > Reported-by: kernel test robot <lkp@xxxxxxxxx>
> > Signed-off-by: Md Haris Iqbal <haris.iqbal@xxxxxxxxxxxxxxx>
> > Signed-off-by: Jack Wang <jinpu.wang@xxxxxxxxxxxxxxx>
> > ---
> >   drivers/block/rnbd/rnbd-clt.c | 7 ++++---
> >   1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c
> > index a199b190c73d..62b77b5dc061 100644
> > --- a/drivers/block/rnbd/rnbd-clt.c
> > +++ b/drivers/block/rnbd/rnbd-clt.c
> > @@ -1365,7 +1365,7 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
> >                                     const char *pathname)
> >   {
> >       struct rnbd_clt_dev *dev;
> > -     int ret;
> > +     int len, ret;
> >
> >       dev = kzalloc_node(sizeof(*dev), GFP_KERNEL, NUMA_NO_NODE);
> >       if (!dev)
> > @@ -1388,12 +1388,13 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
> >               goto out_queues;
> >       }
> >
> > -     dev->pathname = kzalloc(strlen(pathname) + 1, GFP_KERNEL);
> > +     len = strlen(pathname) + 1;
> > +     dev->pathname = kzalloc(len, GFP_KERNEL);
> >       if (!dev->pathname) {
> >               ret = -ENOMEM;
> >               goto out_queues;
> >       }
> > -     strlcpy(dev->pathname, pathname, strlen(pathname) + 1);
> > +     strlcpy(dev->pathname, pathname, len);
> >
> >       dev->clt_device_id      = ret;
> >       dev->sess               = sess;
>
> Please use kstrdup() instead of open-coding it.
Ok, will do it, thanks for the suggestion Bart!
>
> Thanks,
>
> Bart.
>
>
Jack



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux