[PATCH 7/7] Handle snprintf truncation more graceful in thunderx_edac

From: Eric Sesterhenn
Date: Wed Oct 11 2017 - 04:29:03 EST



When snprintf truncates the string, size might underflow
causing a WARN_ON_ONCE in the snprintf in the next iteration.

Signed-off-by: Eric Sesterhenn <eric.sesterhenn@xxxxxxxxxxx>
---
drivers/edac/thunderx_edac.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/edac/thunderx_edac.c b/drivers/edac/thunderx_edac.c
index f35d87519a3e..aedf3412f38c 100644
--- a/drivers/edac/thunderx_edac.c
+++ b/drivers/edac/thunderx_edac.c
@@ -59,6 +59,8 @@ static void decode_register(char *str, size_t size,
descr->type == ERR_CORRECTED ?
"Corrected" : "Uncorrected",
descr->descr);
+ if (ret > size)
+ return;
str += ret;
size -= ret;
}
--
Eric Sesterhenn (Principal Security Consultant)
X41 D-SEC GmbH, Dennewartstr. 25-27, D-52068 Aachen
T: +49 241 9809418-0, Fax: -9
Unternehmenssitz: Aachen, Amtsgericht Aachen: HRB19989
GeschÃftsfÃhrer: Markus Vervier

Attachment: signature.asc
Description: OpenPGP digital signature