From: Arnd Bergmann <arnd@kernel.org>
To: Danil Kipnis <danil.kipnis@cloud.ionos.com>,
Jack Wang <jinpu.wang@cloud.ionos.com>,
Jens Axboe <axboe@kernel.dk>,
Guoqing Jiang <guoqing.jiang@cloud.ionos.com>,
Gioh Kim <gi-oh.kim@cloud.ionos.com>,
Md Haris Iqbal <haris.iqbal@cloud.ionos.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
Colin Ian King <colin.king@canonical.com>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] block/rnbd-clt: fix overlapping snprintf arguments
Date: Tue, 23 Mar 2021 13:55:24 +0100 [thread overview]
Message-ID: <20210323125535.1866249-1-arnd@kernel.org> (raw)
From: Arnd Bergmann <arnd@arndb.de>
The -Wrestrict warning (disabled by default) points out undefined
behavior calling snprintf():
drivers/block/rnbd/rnbd-clt-sysfs.c: In function 'rnbd_clt_get_path_name':
drivers/block/rnbd/rnbd-clt-sysfs.c:486:8: error: 'snprintf' argument 4 overlaps destination object 'buf' [-Werror=restrict]
486 | ret = snprintf(buf, len, "%s@%s", buf, dev->sess->sessname);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/rnbd/rnbd-clt-sysfs.c:472:67: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
472 | static int rnbd_clt_get_path_name(struct rnbd_clt_dev *dev, char *buf,
| ~~~~~~^~~
This can be simplified by using a single snprintf() to print the
whole buffer, avoiding the undefined behavior.
Fixes: 91f4acb2801c ("block/rnbd-clt: support mapping two devices with the same name from different servers")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/block/rnbd/rnbd-clt-sysfs.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c
index d4aa6bfc9555..38251b749664 100644
--- a/drivers/block/rnbd/rnbd-clt-sysfs.c
+++ b/drivers/block/rnbd/rnbd-clt-sysfs.c
@@ -479,11 +479,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;
--
2.29.2
next reply other threads:[~2021-03-23 12:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-23 12:55 Arnd Bergmann [this message]
2021-03-24 10:34 ` [PATCH] block/rnbd-clt: fix overlapping snprintf arguments Jinpu Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210323125535.1866249-1-arnd@kernel.org \
--to=arnd@kernel.org \
--cc=arnd@arndb.de \
--cc=axboe@kernel.dk \
--cc=colin.king@canonical.com \
--cc=danil.kipnis@cloud.ionos.com \
--cc=gi-oh.kim@cloud.ionos.com \
--cc=guoqing.jiang@cloud.ionos.com \
--cc=haris.iqbal@cloud.ionos.com \
--cc=jinpu.wang@cloud.ionos.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox