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

arch/powerpc/kernel: Use %12.12s instead of %12s to avoid memory overflow

for tmp_part->header.name:
it is "Terminating null required only for names < 12 chars".
so need to limit the %.12s for it in printk

additional info:

%12s limit the width, not for the original string output length
if name length is more than 12, it still can be fully displayed.
if name length is less than 12, the ' ' will be filled before name.

%.12s truly limit the original string output length (precision)

Signed-off-by: Chen Gang <gang.chen@asianux.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Chen Gang and committed by
Benjamin Herrenschmidt
e0513d9e ec67ad82

+1 -1
+1 -1
arch/powerpc/kernel/nvram_64.c
··· 210 210 printk(KERN_WARNING "--------%s---------\n", label); 211 211 printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n"); 212 212 list_for_each_entry(tmp_part, &nvram_partitions, partition) { 213 - printk(KERN_WARNING "%4d \t%02x\t%02x\t%d\t%12s\n", 213 + printk(KERN_WARNING "%4d \t%02x\t%02x\t%d\t%12.12s\n", 214 214 tmp_part->index, tmp_part->header.signature, 215 215 tmp_part->header.checksum, tmp_part->header.length, 216 216 tmp_part->header.name);