Skip to contentSkip to conversation

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

PATCH In review Dan Carpenter 3 participants 4 messages Aug 1, 2014 – Nov 11, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

drivers/edac/ghes_edac.c +2 -2
index 8399b4e..b246819 100644
@@ -413,8 +413,8 @@ void ghes_edac_report_mem_error(struct ghes *ghes, int sev,
 
 	/* Generate the trace event */
 	grain_bits = fls_long(e->grain);
-	sprintf(pvt->detail_location, "APEI location: %s %s",
-		e->location, e->other_detail);
+	snprintf(pvt->detail_location, sizeof(pvt->detail_location),
+		 "APEI location: %s %s", e->location, e->other_detail);
 	trace_mc_event(type, e->msg, e->label, e->error_count,
 		       mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer,
 		       PAGES_TO_MiB(e->page_frame_number) | e->offset_in_page,
maintainer
#1 lore raw

Did this one get missed? Mauro?

Quoted 27 lines · Dan Carpenter

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.

drivers/edac/ghes_edac.c +2 -2
index 8399b4e..b246819 100644
@@ -413,8 +413,8 @@ void ghes_edac_report_mem_error(struct ghes *ghes, int sev,
 
 	/* Generate the trace event */
 	grain_bits = fls_long(e->grain);
-	sprintf(pvt->detail_location, "APEI location: %s %s",
-		e->location, e->other_detail);
+	snprintf(pvt->detail_location, sizeof(pvt->detail_location),
+		 "APEI location: %s %s", e->location, e->other_detail);
 	trace_mc_event(type, e->msg, e->label, e->error_count,
 		       mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer,
 		       PAGES_TO_MiB(e->page_frame_number) | e->offset_in_page,
Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
Acked-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter

Em Tue, 11 Nov 2014 17:55:09 +0100
Borislav Petkov <[email protected]> escreveu:

Quoted 1 line

Did this one get missed? Mauro?

Yeah, I missed that, sorry.

I can apply it on my tree, but if you want to apply on yours, feel free to do it, and add my ack:

Quoted 29 lines · Dan Carpenter
Quoted 27 lines

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.

drivers/edac/ghes_edac.c +2 -2
index 8399b4e..b246819 100644
@@ -413,8 +413,8 @@ void ghes_edac_report_mem_error(struct ghes *ghes, int sev,
 
 	/* Generate the trace event */
 	grain_bits = fls_long(e->grain);
-	sprintf(pvt->detail_location, "APEI location: %s %s",
-		e->location, e->other_detail);
+	snprintf(pvt->detail_location, sizeof(pvt->detail_location),
+		 "APEI location: %s %s", e->location, e->other_detail);
 	trace_mc_event(type, e->msg, e->label, e->error_count,
 		       mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer,
 		       PAGES_TO_MiB(e->page_frame_number) | e->offset_in_page,
maintainer
#3 lore raw
In reply to Dan Carpenter
Quoted 11 lines · Mauro Carvalho Chehab

Em Tue, 11 Nov 2014 17:55:09 +0100
Borislav Petkov <[email protected]> escreveu:

Quoted 1 line

Did this one get missed? Mauro?

Yeah, I missed that, sorry.

I can apply it on my tree, but if you want to apply on yours, feel free to do it, and add my ack:

Aha, I see :-)

Ok, done.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--