* [patch] iio:imu: adis16480: show_firmware() buffer too small
@ 2012-11-27 7:31 Dan Carpenter
2012-11-27 18:41 ` Lars-Peter Clausen
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2012-11-27 7:31 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: Lars-Peter Clausen, linux-iio, kernel-janitors
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);
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [patch] iio:imu: adis16480: show_firmware() buffer too small
2012-11-27 7:31 [patch] iio:imu: adis16480: show_firmware() buffer too small Dan Carpenter
@ 2012-11-27 18:41 ` Lars-Peter Clausen
2012-11-30 13:13 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Lars-Peter Clausen @ 2012-11-27 18:41 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Jonathan Cameron, linux-iio, kernel-janitors
On 11/27/2012 08:31 AM, Dan Carpenter wrote:
> 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.
>
Thanks,
Acked-By: Lars-Peter Clausen <lars@metafoo.de>
> 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);
> }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch] iio:imu: adis16480: show_firmware() buffer too small
2012-11-27 18:41 ` Lars-Peter Clausen
@ 2012-11-30 13:13 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2012-11-30 13:13 UTC (permalink / raw)
To: Lars-Peter Clausen
Cc: Dan Carpenter, Jonathan Cameron, linux-iio, kernel-janitors
On 11/27/2012 06:41 PM, Lars-Peter Clausen wrote:
> On 11/27/2012 08:31 AM, Dan Carpenter wrote:
>> 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.
>>
>
>
> Thanks,
>
> Acked-By: Lars-Peter Clausen <lars@metafoo.de>
>
Added to togreg branch of
git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git
>> 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);
>> }
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-11-30 13:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-27 7:31 [patch] iio:imu: adis16480: show_firmware() buffer too small Dan Carpenter
2012-11-27 18:41 ` Lars-Peter Clausen
2012-11-30 13:13 ` Jonathan Cameron
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).