Skip to content

Commit 4a1b41c

Browse files
nvlsianpupennam
authored andcommitted
loader: clear calculation in boot_copy_region()
Introduced mediate variable for express data chunk offset from the beginning of the region. Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent 24f1378 commit 4a1b41c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

boot/bootutil/src/loader.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -965,37 +965,37 @@ boot_copy_region(struct boot_loader_state *state,
965965
}
966966
#endif
967967
if (IS_ENCRYPTED(hdr)) {
968-
if (off + bytes_copied < hdr->ih_hdr_size) {
968+
uint32_t abs_off = off + bytes_copied;
969+
if (abs_off < hdr->ih_hdr_size) {
969970
/* do not decrypt header */
970-
if (off + bytes_copied + chunk_sz > hdr->ih_hdr_size) {
971+
if (abs_off + chunk_sz > hdr->ih_hdr_size) {
971972
/* The lower part of the chunk contains header data */
972973
blk_off = 0;
973-
blk_sz = chunk_sz - (hdr->ih_hdr_size - off -
974-
bytes_copied);
975-
idx = hdr->ih_hdr_size - off - bytes_copied;
974+
blk_sz = chunk_sz - (hdr->ih_hdr_size - abs_off);
975+
idx = hdr->ih_hdr_size - abs_off;
976976
} else {
977977
/* The chunk contains exclusively header data */
978978
blk_sz = 0; /* nothing to decrypt */
979979
}
980980
} else {
981981
idx = 0;
982982
blk_sz = chunk_sz;
983-
blk_off = ((off + bytes_copied) - hdr->ih_hdr_size) & 0xf;
983+
blk_off = (abs_off - hdr->ih_hdr_size) & 0xf;
984984
}
985985

986986
if (blk_sz > 0)
987987
{
988988
tlv_off = BOOT_TLV_OFF(hdr);
989-
if (off + bytes_copied + chunk_sz > tlv_off) {
989+
if (abs_off + chunk_sz > tlv_off) {
990990
/* do not decrypt TLVs */
991-
if (off + bytes_copied >= tlv_off) {
991+
if (abs_off >= tlv_off) {
992992
blk_sz = 0;
993993
} else {
994-
blk_sz = tlv_off - (off + bytes_copied);
994+
blk_sz = tlv_off - abs_off;
995995
}
996996
}
997997
boot_encrypt(BOOT_CURR_ENC(state), image_index, fap_src,
998-
(off + bytes_copied + idx) - hdr->ih_hdr_size, blk_sz,
998+
(abs_off + idx) - hdr->ih_hdr_size, blk_sz,
999999
blk_off, &buf[idx]);
10001000
}
10011001
}

0 commit comments

Comments
 (0)