1
0
Fork 0
mirror of https://github.com/CTCaer/hekate.git synced 2024-11-10 04:21:45 +00:00

r2p/update: Fix check for the 'if not forced' case

This fixes the following case:
When force is 0 and the payload is not hekate, the function jumps to the 'is old' check.

This skips the is magic value check and only does the version check.

In case the foreign payload has a low value on that offset, it causes an overwrite which is unneeded.
This commit is contained in:
CTCaer 2020-01-17 09:35:16 +02:00
parent 5a9bbaf900
commit 91759aba95

View file

@ -256,14 +256,17 @@ bool is_ipl_updated(void *buf, char *path, bool force)
{ {
ipl_ver_meta_t *update_ft = (ipl_ver_meta_t *)(buf + PATCHED_RELOC_SZ + sizeof(boot_cfg_t)); ipl_ver_meta_t *update_ft = (ipl_ver_meta_t *)(buf + PATCHED_RELOC_SZ + sizeof(boot_cfg_t));
bool magic_valid = update_ft->magic == ipl_ver.magic;
bool force_update = force && !magic_valid;
bool is_valid_old = magic_valid && (byte_swap_32(update_ft->version) < byte_swap_32(ipl_ver.version));
// Check if newer version. // Check if newer version.
if (!force && (update_ft->magic == ipl_ver.magic)) if (!force && magic_valid)
if (byte_swap_32(update_ft->version) > byte_swap_32(ipl_ver.version)) if (byte_swap_32(update_ft->version) > byte_swap_32(ipl_ver.version))
return false; return false;
// Update if old or broken. // Update if old or broken.
if ((force && (update_ft->magic != ipl_ver.magic)) || if (force_update || is_valid_old)
(byte_swap_32(update_ft->version) < byte_swap_32(ipl_ver.version)))
{ {
FIL fp; FIL fp;
volatile reloc_meta_t *reloc = (reloc_meta_t *)(IPL_LOAD_ADDR + RELOC_META_OFF); volatile reloc_meta_t *reloc = (reloc_meta_t *)(IPL_LOAD_ADDR + RELOC_META_OFF);