From: Dan Carpenter <dan.carpenter@oracle.com>
To: Jonathan Cameron <jic23@cam.ac.uk>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [patch] iio:imu: adis16480: show_firmware() buffer too small
Date: Tue, 27 Nov 2012 07:31:42 +0000 [thread overview]
Message-ID: <20121127073142.GC8239@elgon.mountain> (raw)
Smatch complains that snprintf() returns the number of characters,
not counting the NUL terminator, which *would* have been printed if
there were enough space. In other words the return value could be more
than sizeof(buf).
In this case, we are printing something like "ff.ff\n" which is at most
6 characters and a NUL so that's not an issue. I changed snprintf() to
scnprintf() to silence the warning.
But since the buffer doesn't include space for the NUL terminator, we
need to make it bigger or the "\n" will be truncated off.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/iio/imu/adis16480.c b/drivers/iio/imu/adis16480.c
index a080b35..150d7fa 100644
--- a/drivers/iio/imu/adis16480.c
+++ b/drivers/iio/imu/adis16480.c
@@ -125,7 +125,7 @@ static ssize_t adis16480_show_firmware_revision(struct file *file,
char __user *userbuf, size_t count, loff_t *ppos)
{
struct adis16480 *adis16480 = file->private_data;
- char buf[6];
+ char buf[7];
size_t len;
u16 rev;
int ret;
@@ -134,7 +134,7 @@ static ssize_t adis16480_show_firmware_revision(struct file *file,
if (ret < 0)
return ret;
- len = snprintf(buf, sizeof(buf), "%x.%x\n", rev >> 8, rev & 0xff);
+ len = scnprintf(buf, sizeof(buf), "%x.%x\n", rev >> 8, rev & 0xff);
return simple_read_from_buffer(userbuf, count, ppos, buf, len);
}
next reply other threads:[~2012-11-27 7:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-27 7:31 Dan Carpenter [this message]
2012-11-27 18:41 ` [patch] iio:imu: adis16480: show_firmware() buffer too small Lars-Peter Clausen
2012-11-30 13:13 ` Jonathan Cameron
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=20121127073142.GC8239@elgon.mountain \
--to=dan.carpenter@oracle.com \
--cc=jic23@cam.ac.uk \
--cc=kernel-janitors@vger.kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@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;
as well as URLs for NNTP newsgroup(s).