]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
block/rnbd-clt-sysfs: Remove copy buffer overlap in rnbd_clt_get_path_name
authorDima Stepanov <dmitrii.stepanov@cloud.ionos.com>
Mon, 19 Apr 2021 07:37:21 +0000 (09:37 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 May 2021 08:49:58 +0000 (10:49 +0200)
[ Upstream commit 3db7cf55d532a15ea26b4a14e8f8729ccd96fd22 ]

cppcheck report the following error:
  rnbd/rnbd-clt-sysfs.c:522:36: error: The variable 'buf' is used both
  as a parameter and as destination in snprintf(). The origin and
  destination buffers overlap. Quote from glibc (C-library)
  documentation
  (http://www.gnu.org/software/libc/manual/html_mono/libc.html#Formatted-Output-Functions):
  "If copying takes place between objects that overlap as a result of a
  call to sprintf() or snprintf(), the results are undefined."
  [sprintfOverlappingData]
Fix it by initializing the buf variable in the first snprintf call.

Fixes: 91f4acb2801c ("block/rnbd-clt: support mapping two devices")
Signed-off-by: Dima Stepanov <dmitrii.stepanov@ionos.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: Gioh Kim <gi-oh.kim@cloud.ionos.com>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Link: https://lore.kernel.org/r/20210419073722.15351-19-gi-oh.kim@ionos.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/block/rnbd/rnbd-clt-sysfs.c

index 526c77cd7a506ce6e75e90fe8c342c191652e1c6..49ad400a5225572705f9ba550869f77308911716 100644 (file)
@@ -483,11 +483,7 @@ static int rnbd_clt_get_path_name(struct rnbd_clt_dev *dev, char *buf,
        while ((s = strchr(pathname, '/')))
                s[0] = '!';
 
-       ret = snprintf(buf, len, "%s", pathname);
-       if (ret >= len)
-               return -ENAMETOOLONG;
-
-       ret = snprintf(buf, len, "%s@%s", buf, dev->sess->sessname);
+       ret = snprintf(buf, len, "%s@%s", pathname, dev->sess->sessname);
        if (ret >= len)
                return -ENAMETOOLONG;