diff mbox series

[PATCHv3,for-next,18/19] block/rnbd-clt-sysfs: Remove copy buffer overlap in rnbd_clt_get_path_name

Message ID 20210406070716.168541-19-gi-oh.kim@ionos.com (mailing list archive)
State New, archived
Headers show
Series Misc update for rnbd | expand

Commit Message

Gioh Kim April 6, 2021, 7:07 a.m. UTC
From: Dima Stepanov <dmitrii.stepanov@cloud.ionos.com>

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>
---
 drivers/block/rnbd/rnbd-clt-sysfs.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Comments

Gioh Kim April 6, 2021, 8:25 a.m. UTC | #1
On Tue, Apr 6, 2021 at 9:07 AM Gioh Kim <gi-oh.kim@ionos.com> wrote:
>
> From: Dima Stepanov <dmitrii.stepanov@cloud.ionos.com>
>
> 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>
+ Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
diff mbox series

Patch

diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c
index 5609b9cdc289..062c52e7a468 100644
--- a/drivers/block/rnbd/rnbd-clt-sysfs.c
+++ b/drivers/block/rnbd/rnbd-clt-sysfs.c
@@ -515,11 +515,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;