Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/early: Use scnprintf() instead of sprintf()

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>

+9 -9
+9 -9
arch/s390/kernel/early.c
··· 120 120 EBCASC(mach->type, sizeof(mach->type)); 121 121 EBCASC(mach->model, sizeof(mach->model)); 122 122 EBCASC(mach->model_capacity, sizeof(mach->model_capacity)); 123 - sprintf(mstr, "%-16.16s %-4.4s %-16.16s %-16.16s", 124 - mach->manufacturer, mach->type, 125 - mach->model, mach->model_capacity); 123 + scnprintf(mstr, sizeof(mstr), "%-16.16s %-4.4s %-16.16s %-16.16s", 124 + mach->manufacturer, mach->type, 125 + mach->model, mach->model_capacity); 126 126 strim_all(mstr); 127 127 if (stsi(vm, 3, 2, 2) == 0 && vm->count) { 128 128 EBCASC(vm->vm[0].cpi, sizeof(vm->vm[0].cpi)); 129 - sprintf(hvstr, "%-16.16s", vm->vm[0].cpi); 129 + scnprintf(hvstr, sizeof(hvstr), "%-16.16s", vm->vm[0].cpi); 130 130 strim_all(hvstr); 131 131 } else { 132 - sprintf(hvstr, "%s", 133 - machine_is_lpar() ? "LPAR" : 134 - machine_is_vm() ? "z/VM" : 135 - machine_is_kvm() ? "KVM" : "unknown"); 132 + scnprintf(hvstr, sizeof(hvstr), "%s", 133 + machine_is_lpar() ? "LPAR" : 134 + machine_is_vm() ? "z/VM" : 135 + machine_is_kvm() ? "KVM" : "unknown"); 136 136 } 137 - sprintf(arch_hw_string, "HW: %s (%s)", mstr, hvstr); 137 + scnprintf(arch_hw_string, sizeof(arch_hw_string), "HW: %s (%s)", mstr, hvstr); 138 138 dump_stack_set_arch_desc("%s (%s)", mstr, hvstr); 139 139 } 140 140