]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
s390/dcss: Use scnprintf() instead of sprintf()
authorHeiko Carstens <hca@linux.ibm.com>
Tue, 7 Oct 2025 09:05:03 +0000 (11:05 +0200)
committerHeiko Carstens <hca@linux.ibm.com>
Tue, 21 Oct 2025 08:17:30 +0000 (10:17 +0200)
Use scnprintf() instead of sprintf() for those cases where the destination
is an array and the size of the array is known at compile time.

This prevents theoretical buffer overflows, but also avoids that people
again and again spend time to figure out if the code is actually safe.

Reviewed-by: Jan Polensky <japo@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
drivers/s390/block/dcssblk.c

index 86fef4b15015d16e26d6de335bc6cb88f2e6eda2..57d691ed0a63fa12a725f44101c22408c4953e82 100644 (file)
@@ -674,8 +674,8 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
        rc = dcssblk_assign_free_minor(dev_info);
        if (rc)
                goto release_gd;
-       sprintf(dev_info->gd->disk_name, "dcssblk%d",
-               dev_info->gd->first_minor);
+       scnprintf(dev_info->gd->disk_name, sizeof(dev_info->gd->disk_name),
+                 "dcssblk%d", dev_info->gd->first_minor);
        list_add_tail(&dev_info->lh, &dcssblk_devices);
 
        if (!try_module_get(THIS_MODULE)) {