From: Takashi Iwai Date: Wed, 11 Mar 2020 07:35:40 +0000 (+0100) Subject: drm: sysfs: Use scnprintf() for avoiding potential buffer overflow X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=9b9f2219b2c4fa3d1a41245cdc263d09a4c9ad92;p=openwrt%2Fstaging%2Fblogic.git drm: sysfs: Use scnprintf() for avoiding potential buffer overflow Since snprintf() returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing with scnprintf(). Signed-off-by: Takashi Iwai Reviewed-by: Thomas Zimmermann Signed-off-by: Thomas Zimmermann Link: https://patchwork.freedesktop.org/patch/msgid/20200311073540.7108-1-tiwai@suse.de --- diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c index 2e83c3d72af9..939f0032aab1 100644 --- a/drivers/gpu/drm/drm_sysfs.c +++ b/drivers/gpu/drm/drm_sysfs.c @@ -228,7 +228,7 @@ static ssize_t modes_show(struct device *device, mutex_lock(&connector->dev->mode_config.mutex); list_for_each_entry(mode, &connector->modes, head) { - written += snprintf(buf + written, PAGE_SIZE - written, "%s\n", + written += scnprintf(buf + written, PAGE_SIZE - written, "%s\n", mode->name); } mutex_unlock(&connector->dev->mode_config.mutex);