aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDima Stepanov <[email protected]>2021-04-19 09:37:21 +0200
committerJens Axboe <[email protected]>2021-04-20 08:59:04 -0600
commit3db7cf55d532a15ea26b4a14e8f8729ccd96fd22 (patch)
tree0ac05c13e28587fd54c22df7ee317b7c6ce13a99
parent503438a4f29e83bd21af60288ae6a6644af5de6f (diff)
block/rnbd-clt-sysfs: Remove copy buffer overlap in rnbd_clt_get_path_name
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 <[email protected]> Cc: Arnd Bergmann <[email protected]> Signed-off-by: Jack Wang <[email protected]> Signed-off-by: Gioh Kim <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
-rw-r--r--drivers/block/rnbd/rnbd-clt-sysfs.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c
index f3a5a62b2062..042566b47bd9 100644
--- a/drivers/block/rnbd/rnbd-clt-sysfs.c
+++ b/drivers/block/rnbd/rnbd-clt-sysfs.c
@@ -514,11 +514,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;