From: Andreas Reichel <[email protected]> Only write environment if ustate differs from the value it is set to. This reduces the risk of environment corruption.
Add missing CRC calculation to enable resetting invalid configurations without making those invalid, i.e. two configurations with both ustate == INSTALLED can now be properly reset to ustate == OK, without rendering the inactive config invalid. Signed-off-by: Andreas Reichel <[email protected]> --- env/env_api.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/env/env_api.c b/env/env_api.c index 29808ff..abfa49a 100644 --- a/env/env_api.c +++ b/env/env_api.c @@ -188,10 +188,14 @@ int ebg_env_setglobalstate(ebgenv_t *e, uint16_t ustate) if (!env) { continue; } - env->data->ustate = ustate; - if (!bgenv_write(env)) { - (void)bgenv_close(env); - return -EIO; + if (env->data->ustate != ustate) { + env->data->ustate = ustate; + env->data->crc32 = crc32(0, (Bytef *)env->data, + sizeof(BG_ENVDATA) - sizeof(env->data->crc32)); + if (!bgenv_write(env)) { + (void)bgenv_close(env); + return -EIO; + } } if (!bgenv_close(env)) { return -EIO; -- 2.15.0 -- You received this message because you are subscribed to the Google Groups "EFI Boot Guard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/efibootguard-dev/20171117163213.32262-3-andreas.reichel.ext%40siemens.com. For more options, visit https://groups.google.com/d/optout.
