mtdparts: fixed buffer overflow bug
PATCH 1/1 mtdparts: fixed buffer overflow bug
In the case that there was no name defined for a partition the code assumes that name_len is 22 and therefore allocates exactly that space for a dummy name. But the function sprintf() first resolves "0x%08llx at 0x%08llx" to a string that is longer than 22 bytes. This leads to a buffer overflow. The replacement function snprintf() limits the copied bytes to name_len and therefore avoids the buffer overflow.
--- cmd/mtdparts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/mtdparts.c +1 -1
@@ -691,7 +691,7 @@ static int part_parse(const char *const partdef, const char **ret, struct part_i part->auto_name =0 ; }else {/* auto generated name in form of size at offset */ -sprintf (part->name,"0x%08llx at 0x%08llx" , size, offset); +snprintf (part->name, name_len,"0x%08llx at 0x%08llx" , size, offset); part->auto_name =1 ; }
Signature · 1 line
2.17.0
Quoted 9 lines · Kay Potthoff
In the case that there was no name defined for a partition the code assumes that
name_lenis 22 and therefore allocates exactly that space for a dummy name. But the functionsprintf()first resolves "0x%08llx at 0x%08llx" to a string that is longer than 22 bytes. This leads to a buffer overflow. The replacement functionsnprintf()limits the copied bytes toname_lenand therefore avoids the buffer overflow.Signed-off-by Kay Potthoff <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180726/57b652f5/attachment.sig>