greybus: interface: fix potential attribute-buffer overflow

Use scnprintf in the generic attribute helper, which does not currently
check for buffer overflow.

The attribute helper is used to print generic strings, which could
potentially overflow the buffer. Note that the only strings currently
exported are taken from greybus string descriptors and should therefore
be limited to 255 chars.

Signed-off-by: Johan Hovold <johan@hovoldconsulting.com>
Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
This commit is contained in:
Johan Hovold 2015-09-01 12:25:27 +02:00
parent 287bba82fe
commit 505c9d27b8
1 changed files with 1 additions and 1 deletions

View File

@ -16,7 +16,7 @@ static ssize_t field##_show(struct device *dev, \
char *buf) \ char *buf) \
{ \ { \
struct gb_interface *intf = to_gb_interface(dev); \ struct gb_interface *intf = to_gb_interface(dev); \
return sprintf(buf, "%"#type"\n", intf->field); \ return scnprintf(buf, PAGE_SIZE, "%"#type"\n", intf->field); \
} \ } \
static DEVICE_ATTR_RO(field) static DEVICE_ATTR_RO(field)