Skip to contentSkip to conversation

part_efi: In is_gpt_valid() check argument validity before allocation

PATCH In review Tom Rini 1 participant 2 messages Oct 3, 2017 – Oct 17, 2017

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 part_efi: In is_gpt_valid() check argument validity before allocation

While this goes somewhat against normal coding style we should ensure that dev_desc is not NULL before we dereference it in allocation of legacy_mbr.

Reported-by Coverity (CID: 167292)
---
 disk/part_efi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
disk/part_efi.c +3 -2
index 208bb14ee88e..1b526c2a79b9 100644
@@ -923,13 +923,14 @@ static int is_pmbr_valid(legacy_mbr * mbr)
 static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
 			gpt_header *pgpt_head, gpt_entry **pgpt_pte)
 {
-	ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz);
-
+	/* Confirm valid arguments prior to allocation. */
 	if (!dev_desc || !pgpt_head) {
 		printf("%s: Invalid Argument(s)\n", __func__);
 		return 0;
 	}
 
+	ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz);
+
 	/* Read MBR Header from device */
 	if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) {
 		printf("*** ERROR: Can't read MBR header ***\n");
Signature · 1 line
2.7.4
author
#1 lore raw
Quoted 6 lines · Tom Rini

While this goes somewhat against normal coding style we should ensure that dev_desc is not NULL before we dereference it in allocation of legacy_mbr.

Reported-by Coverity (CID: 167292)

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/20171016/5763f57b/attachment.sig>