diff mbox

[U-Boot,v1,2/2] kwbimage: fix size computations for v1 images

Message ID 1448613827-2349-3-git-send-email-reinhard.pfau@gdsys.cc
State Accepted
Delegated to: Stefan Roese
Headers show

Commit Message

Reinhard Pfau Nov. 27, 2015, 8:43 a.m. UTC
Fix computation of haeder size and binary header size.
Size of opt header and some 32bit values were not taken into account. This could
result in invalid boot images (due to the wrong binary header size, the image could
claim to have another extension header after the binary extension although there
is none).

Use "uint32_t" instead of "unsigned int" for header size computation.

Signed-off-by: Reinhard Pfau <reinhard.pfau@gdsys.cc>
Cc: Luka Perkov <luka.perkov@sartura.hr>
---

 tools/kwbimage.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Stefan Roese Nov. 27, 2015, 10:31 a.m. UTC | #1
On 27.11.2015 09:43, Reinhard Pfau wrote:
> Fix computation of haeder size and binary header size.
> Size of opt header and some 32bit values were not taken into account. This could
> result in invalid boot images (due to the wrong binary header size, the image could
> claim to have another extension header after the binary extension although there
> is none).
>
> Use "uint32_t" instead of "unsigned int" for header size computation.
>
> Signed-off-by: Reinhard Pfau <reinhard.pfau@gdsys.cc>
> Cc: Luka Perkov <luka.perkov@sartura.hr>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan
diff mbox

Patch

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index afba73f..ff06b19 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -324,8 +324,9 @@  static size_t image_headersz_v1(struct image_tool_params *params,
 			return 0;
 		}
 
-		headersz += s.st_size +
-			binarye->binary.nargs * sizeof(unsigned int);
+		headersz += sizeof(struct opt_hdr_v1) +
+			s.st_size +
+			(binarye->binary.nargs + 2) * sizeof(uint32_t);
 		if (hasext)
 			*hasext = 1;
 	}
@@ -419,7 +420,7 @@  static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
 		fstat(fileno(bin), &s);
 
 		binhdrsz = sizeof(struct opt_hdr_v1) +
-			(binarye->binary.nargs + 1) * sizeof(unsigned int) +
+			(binarye->binary.nargs + 2) * sizeof(uint32_t) +
 			s.st_size;
 		binhdrsz = ALIGN_SUP(binhdrsz, 32);
 		hdr->headersz_lsb = cpu_to_le16(binhdrsz & 0xFFFF);