Commit 598db581 authored by Kees Cook's avatar Kees Cook Committed by Jonathan Cameron

iio: force snprintf for PAGE_SIZE bufs

This is a tiny preventative measure to make sure we can't write beyond
PAGE_SIZE on the buffers being used in sysfs for iio. There is currently
no way for this to happen, but the change makes this code more robust
for the future.
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 24e7d799
...@@ -340,7 +340,7 @@ ssize_t iio_enum_read(struct iio_dev *indio_dev, ...@@ -340,7 +340,7 @@ ssize_t iio_enum_read(struct iio_dev *indio_dev,
else if (i >= e->num_items) else if (i >= e->num_items)
return -EINVAL; return -EINVAL;
return sprintf(buf, "%s\n", e->items[i]); return snprintf(buf, PAGE_SIZE, "%s\n", e->items[i]);
} }
EXPORT_SYMBOL_GPL(iio_enum_read); EXPORT_SYMBOL_GPL(iio_enum_read);
...@@ -820,7 +820,7 @@ static ssize_t iio_show_dev_name(struct device *dev, ...@@ -820,7 +820,7 @@ static ssize_t iio_show_dev_name(struct device *dev,
char *buf) char *buf)
{ {
struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev *indio_dev = dev_to_iio_dev(dev);
return sprintf(buf, "%s\n", indio_dev->name); return snprintf(buf, PAGE_SIZE, "%s\n", indio_dev->name);
} }
static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL); static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment