@@ -215,6 +215,7 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
215215 uint32_t * img_size ;
216216 uint32_t total_size ;
217217 WB_PATCH_CTX ctx ;
218+ uint32_t cur_v , upd_v , delta_base_v ;
218219#ifdef EXT_ENCRYPTED
219220 uint8_t key [ENCRYPT_KEY_SIZE ];
220221 uint8_t nonce [ENCRYPT_NONCE_SIZE ];
@@ -237,20 +238,24 @@ static int wolfBoot_delta_update(struct wolfBoot_image *boot,
237238 if (wolfBoot_get_delta_info (PART_UPDATE , inverse , & img_offset , & img_size ) < 0 ) {
238239 return -1 ;
239240 }
241+ cur_v = wolfBoot_current_firmware_version ();
242+ upd_v = wolfBoot_update_firmware_version ();
243+ delta_base_v = wolfBoot_get_diffbase_version (PART_UPDATE );
240244 if (inverse ) {
241- uint32_t cur_v , upd_v , delta_base_v ;
242- cur_v = wolfBoot_current_firmware_version ();
243- upd_v = wolfBoot_update_firmware_version ();
244- delta_base_v = wolfBoot_get_diffbase_version (PART_UPDATE );
245245 if (((cur_v == upd_v ) && (delta_base_v < cur_v )) || resume_inverse ) {
246246 ret = wb_patch_init (& ctx , boot -> hdr , boot -> fw_size +
247247 IMAGE_HEADER_SIZE , update -> hdr + * img_offset , * img_size );
248248 } else {
249249 ret = -1 ;
250250 }
251251 } else {
252- ret = wb_patch_init (& ctx , boot -> hdr , boot -> fw_size + IMAGE_HEADER_SIZE ,
253- update -> hdr + IMAGE_HEADER_SIZE , * img_size );
252+ if (cur_v != delta_base_v ) {
253+ /* Wrong base image, cannot apply delta patch */
254+ ret = -1 ;
255+ } else {
256+ ret = wb_patch_init (& ctx , boot -> hdr , boot -> fw_size + IMAGE_HEADER_SIZE ,
257+ update -> hdr + IMAGE_HEADER_SIZE , * img_size );
258+ }
254259 }
255260 if (ret < 0 )
256261 goto out ;
0 commit comments