Thread (10 messages) 10 messages, 2 authors, 2020-12-09

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

From: Jinpu Wang <jinpu.wang@cloud.ionos.com>
Date: 2020-12-09 16:14:59

On Wed, Dec 9, 2020 at 5:08 PM Bart Van Assche [off-list ref] wrote:
On 12/9/20 12:20 AM, Jack Wang wrote:
quoted
From: Md Haris Iqbal <redacted>

The kernel test robot triggerred the following warning,
quoted
quoted
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 <redacted>
Signed-off-by: Md Haris Iqbal <redacted>
Signed-off-by: Jack Wang <jinpu.wang@cloud.ionos.com>
---
  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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help