forked from Minki/linux
leds: do not overflow sysfs buffer in led_trigger_show
Per the documentation, use scnprintf instead of sprintf to ensure there is never more than PAGE_SIZE bytes of trigger names put into the buffer. Signed-off-by: Nathan Sullivan <nathan.sullivan@ni.com> Signed-off-by: Zach Brown <zach.brown@ni.com> Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
This commit is contained in:
parent
50237863c4
commit
3b9b95363c
@ -81,21 +81,23 @@ ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
|
|||||||
down_read(&led_cdev->trigger_lock);
|
down_read(&led_cdev->trigger_lock);
|
||||||
|
|
||||||
if (!led_cdev->trigger)
|
if (!led_cdev->trigger)
|
||||||
len += sprintf(buf+len, "[none] ");
|
len += scnprintf(buf+len, PAGE_SIZE - len, "[none] ");
|
||||||
else
|
else
|
||||||
len += sprintf(buf+len, "none ");
|
len += scnprintf(buf+len, PAGE_SIZE - len, "none ");
|
||||||
|
|
||||||
list_for_each_entry(trig, &trigger_list, next_trig) {
|
list_for_each_entry(trig, &trigger_list, next_trig) {
|
||||||
if (led_cdev->trigger && !strcmp(led_cdev->trigger->name,
|
if (led_cdev->trigger && !strcmp(led_cdev->trigger->name,
|
||||||
trig->name))
|
trig->name))
|
||||||
len += sprintf(buf+len, "[%s] ", trig->name);
|
len += scnprintf(buf+len, PAGE_SIZE - len, "[%s] ",
|
||||||
|
trig->name);
|
||||||
else
|
else
|
||||||
len += sprintf(buf+len, "%s ", trig->name);
|
len += scnprintf(buf+len, PAGE_SIZE - len, "%s ",
|
||||||
|
trig->name);
|
||||||
}
|
}
|
||||||
up_read(&led_cdev->trigger_lock);
|
up_read(&led_cdev->trigger_lock);
|
||||||
up_read(&triggers_list_lock);
|
up_read(&triggers_list_lock);
|
||||||
|
|
||||||
len += sprintf(len+buf, "\n");
|
len += scnprintf(len+buf, PAGE_SIZE - len, "\n");
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(led_trigger_show);
|
EXPORT_SYMBOL_GPL(led_trigger_show);
|
||||||
|
Loading…
Reference in New Issue
Block a user