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)
committerJens Axboe <axboe@kernel.dk>
Tue, 20 Apr 2021 14:59:04 +0000 (08:59 -0600)
commit3db7cf55d532a15ea26b4a14e8f8729ccd96fd22
tree0ac05c13e28587fd54c22df7ee317b7c6ce13a99
parent503438a4f29e83bd21af60288ae6a6644af5de6f
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 <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>
drivers/block/rnbd/rnbd-clt-sysfs.c