Commit 76b391cdee022b2fe2ad5627ec8ee7ebab046c1c

Authored by Reinhard Pfau
Committed by Luka Perkov
1 parent a8840dced0

tools/kwbimage: fix size computations for v1 images

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>
Reviewed-by: Stefan Roese <sr@denx.de>
Cc: Luka Perkov <luka.perkov@sartura.hr>

Showing 1 changed file with 4 additions and 3 deletions Side-by-side Diff

... ... @@ -324,8 +324,9 @@
324 324 return 0;
325 325 }
326 326  
327   - headersz += s.st_size +
328   - binarye->binary.nargs * sizeof(unsigned int);
  327 + headersz += sizeof(struct opt_hdr_v1) +
  328 + s.st_size +
  329 + (binarye->binary.nargs + 2) * sizeof(uint32_t);
329 330 if (hasext)
330 331 *hasext = 1;
331 332 }
... ... @@ -419,7 +420,7 @@
419 420 fstat(fileno(bin), &s);
420 421  
421 422 binhdrsz = sizeof(struct opt_hdr_v1) +
422   - (binarye->binary.nargs + 1) * sizeof(unsigned int) +
  423 + (binarye->binary.nargs + 2) * sizeof(uint32_t) +
423 424 s.st_size;
424 425  
425 426 /*