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

ghes_edac: Use snprintf() to silence a static checker warning

My static checker complains because the "e->location" has up to 256
characters but we are copying it into the "pvt->detail_location" which
only has space for 240 characters. That's not counting the surrounding
text and the "e->other_detail" string which can be over 80 characters
long.

I am not familiar with this code but presumably it normally works.
Let's add a limit though for safety.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Link: http://lkml.kernel.org/r/20140801082514.GD28869@mwanda
Signed-off-by: Borislav Petkov <bp@suse.de>

authored by

Dan Carpenter and committed by
Borislav Petkov
665aa8cd f5b10c45

+2 -2
+2 -2
drivers/edac/ghes_edac.c
··· 413 413 414 414 /* Generate the trace event */ 415 415 grain_bits = fls_long(e->grain); 416 - sprintf(pvt->detail_location, "APEI location: %s %s", 417 - e->location, e->other_detail); 416 + snprintf(pvt->detail_location, sizeof(pvt->detail_location), 417 + "APEI location: %s %s", e->location, e->other_detail); 418 418 trace_mc_event(type, e->msg, e->label, e->error_count, 419 419 mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer, 420 420 PAGES_TO_MiB(e->page_frame_number) | e->offset_in_page,