]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
s390/early: Use scnprintf() instead of sprintf()
authorHeiko Carstens <hca@linux.ibm.com>
Tue, 7 Oct 2025 09:05:01 +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>
arch/s390/kernel/early.c

index 544e5403dd917e7162daf307953e7b9584635e64..f4cab46a3e66fbae40f48a20a68fc391de48c1b7 100644 (file)
@@ -120,21 +120,21 @@ static noinline __init void setup_arch_string(void)
        EBCASC(mach->type, sizeof(mach->type));
        EBCASC(mach->model, sizeof(mach->model));
        EBCASC(mach->model_capacity, sizeof(mach->model_capacity));
-       sprintf(mstr, "%-16.16s %-4.4s %-16.16s %-16.16s",
-               mach->manufacturer, mach->type,
-               mach->model, mach->model_capacity);
+       scnprintf(mstr, sizeof(mstr), "%-16.16s %-4.4s %-16.16s %-16.16s",
+                 mach->manufacturer, mach->type,
+                 mach->model, mach->model_capacity);
        strim_all(mstr);
        if (stsi(vm, 3, 2, 2) == 0 && vm->count) {
                EBCASC(vm->vm[0].cpi, sizeof(vm->vm[0].cpi));
-               sprintf(hvstr, "%-16.16s", vm->vm[0].cpi);
+               scnprintf(hvstr, sizeof(hvstr), "%-16.16s", vm->vm[0].cpi);
                strim_all(hvstr);
        } else {
-               sprintf(hvstr, "%s",
-                       machine_is_lpar() ? "LPAR" :
-                       machine_is_vm() ? "z/VM" :
-                       machine_is_kvm() ? "KVM" : "unknown");
+               scnprintf(hvstr, sizeof(hvstr), "%s",
+                         machine_is_lpar() ? "LPAR" :
+                         machine_is_vm() ? "z/VM" :
+                         machine_is_kvm() ? "KVM" : "unknown");
        }
-       sprintf(arch_hw_string, "HW: %s (%s)", mstr, hvstr);
+       scnprintf(arch_hw_string, sizeof(arch_hw_string), "HW: %s (%s)", mstr, hvstr);
        dump_stack_set_arch_desc("%s (%s)", mstr, hvstr);
 }