mtdparts: Fix final outstanding issue reported by Coverity
PATCH 1/1 mtdparts: Fix final outstanding issue reported by Coverity
As part of fixing the previously reported issues, it was missed that in the case of mtdparts_init() we need to make sure that tmp_ep is long enough to contain PARTITION_MAXLEN and a NULL termination. Then, to be sure the buffer is NULL terminated, zero the entire buffer rather than just ensuring the first character is NULL.
--- cmd/mtdparts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
cmd/mtdparts.c +2 -2
@@ -1726,7 +1726,7 @@ int mtdparts_init(void)const char *ids, *parts;const char *current_partition;int ids_changed; -char tmp_ep[PARTITION_MAXLEN ]; +char tmp_ep[PARTITION_MAXLEN +1 ];char tmp_parts[MTDPARTS_MAXLEN ];debug ("\n---mtdparts_init---\n" );
@@ -1750,7 +1750,7 @@ int mtdparts_init(void)/* save it for later parsing, cannot rely on current partition pointer * as 'partition' variable may be updated during init */ - tmp_ep[0 ] ='\0' ; +memset (tmp_parts,0 ,sizeof (tmp_parts));if (current_partition)strncpy (tmp_ep, current_partition,PARTITION_MAXLEN );
Signature · 1 line
1.9.1
Quoted 10 lines · Tom Rini
As part of fixing the previously reported issues, it was missed that in the case of
mtdparts_init()we need to make sure thattmp_epis long enough to containPARTITION_MAXLENand a NULL termination. Then, to be sure the buffer is NULL terminated, zero the entire buffer rather than just ensuring the first character is NULL.Cc Lothar Waßmann <[email protected]>Cc Maxime Ripard <[email protected]>Reported-by Coverity (CID: 166329)Signed-off-by Tom Rini <[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: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170826/996d56eb/attachment.sig>