Skip to content

Commit

Permalink
Delta update fixes
Browse files Browse the repository at this point in the history
- img_size: use 32-bit variable
- remove '+1' from pa_start calculation
- fix broken delta.c wb_diff check for distance between matching
  patterns (root cause for the delta+encrypt bug)
  • Loading branch information
danielinux committed Nov 4, 2023
1 parent 90ecd9f commit f4e0cc6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/delta.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int wb_diff_init(WB_DIFF_CTX *ctx, uint8_t *src_a, uint32_t len_a, uint8_t *src_
int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len);
int wb_patch_init(WB_PATCH_CTX *bm, uint8_t *src, uint32_t ssz, uint8_t *patch, uint32_t psz);
int wb_patch(WB_PATCH_CTX *ctx, uint8_t *dst, uint32_t len);
int wolfBoot_get_delta_info(uint8_t part, int inverse, uint32_t **img_offset, uint16_t **img_size);
int wolfBoot_get_delta_info(uint8_t part, int inverse, uint32_t **img_offset, uint32_t **img_size);

#endif

5 changes: 3 additions & 2 deletions src/delta.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len)
* base for the sectors that have already been updated.
*/

pa_start = (WOLFBOOT_SECTOR_SIZE + 1) * page_start;
pa_start = WOLFBOOT_SECTOR_SIZE * page_start;
pa = ctx->src_a + pa_start;
while (((uintptr_t)(pa - ctx->src_a) < (uintptr_t)ctx->size_a) && (p_off < len)) {
if ((uintptr_t)(ctx->size_a - (pa - ctx->src_a)) < BLOCK_HDR_SIZE)
Expand Down Expand Up @@ -273,7 +273,8 @@ int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len)
/* Don't try matching backwards if the distance between the two
* blocks is smaller than one sector.
*/
if (WOLFBOOT_SECTOR_SIZE > (pb - ctx->src_b) - (page_start * WOLFBOOT_SECTOR_SIZE))
if (WOLFBOOT_SECTOR_SIZE > (page_start * WOLFBOOT_SECTOR_SIZE)
- (pb - ctx->src_b))
break;

if ((memcmp(pb, (ctx->src_b + ctx->off_b), BLOCK_HDR_SIZE) == 0)) {
Expand Down
2 changes: 1 addition & 1 deletion src/update_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
uint32_t offset = 0;
uint16_t ptr_len;
uint32_t *img_offset;
uint16_t *img_size;
uint32_t *img_size;
uint32_t total_size;
WB_PATCH_CTX ctx;
#ifdef EXT_ENCRYPTED
Expand Down

0 comments on commit f4e0cc6

Please sign in to comment.