drm: sysfs: Use scnprintf() for avoiding potential buffer overflow
authorTakashi Iwai <tiwai@suse.de>
Wed, 11 Mar 2020 07:35:40 +0000 (08:35 +0100)
committerThomas Zimmermann <tzimmermann@suse.de>
Wed, 11 Mar 2020 13:54:09 +0000 (14:54 +0100)
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 <tiwai@suse.de>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20200311073540.7108-1-tiwai@suse.de
drivers/gpu/drm/drm_sysfs.c

index 2e83c3d72af9793ca06b7e6411cb0d2f08d2ce96..939f0032aab18b00e837109ad1b16b81d73c8b19 100644 (file)
@@ -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);