From: Jan Kiszka <[email protected]> ebg_env_getglobalstate neither used nor needs a concrete environment for retrieving the effective state over all envs. The passed parameter has always been ignored and was probably only introduced to have a consistent signature compared to ebg_env_setglobalstate or other functions.
At the same time, opening and closing an env via ebg_env_open_current and ebg_env_close is unfortunately not side-effect free which can cause surprises to users, see e.g. [1]. It is therefore better to avoid any needless opening of envs by officially declaring the parameter as reserved, just asking the user to pass NULL from now on. We do not want to change our API for existing users, though, and therefore do not enforce the parameter to be actually NULL. Thus, users can continue to pass valid envs as well. However, we now need to make sure that bgenv_init is also called from ebg_env_getglobalstate as this is otherwise done by ebg_env_create_new or ebg_env_open_current. [1] https://groups.google.com/g/efibootguard-dev/c/hAFE-LQ5cvc Signed-off-by: Jan Kiszka <[email protected]> --- Changes in v2: - initialize bgenv from ebg_env_setglobalstate env/env_api.c | 7 ++++++- include/ebgenv.h | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/env/env_api.c b/env/env_api.c index 0feb127..0890771 100644 --- a/env/env_api.c +++ b/env/env_api.c @@ -176,11 +176,16 @@ uint32_t ebg_env_user_free(ebgenv_t *e) return bgenv_user_free(((BGENV *)e->bgenv)->data->userdata); } -uint16_t ebg_env_getglobalstate(ebgenv_t __attribute__((unused)) *e) +uint16_t ebg_env_getglobalstate(void __attribute__((unused)) *reserved) { BGENV *env; int res = USTATE_UNKNOWN; + if (!bgenv_init()) { + errno = EIO; + return res; + } + /* Test for rolled-back condition. */ for (int i = 0; i < ENV_NUM_CONFIG_PARTS; i++) { env = bgenv_open_by_index(i); diff --git a/include/ebgenv.h b/include/ebgenv.h index c62d271..60ba81c 100644 --- a/include/ebgenv.h +++ b/include/ebgenv.h @@ -136,10 +136,10 @@ int ebg_env_get_ex(ebgenv_t *e, char *key, uint64_t *datatype, uint8_t *buffer, uint32_t ebg_env_user_free(ebgenv_t *e); /** @brief Get global ustate value, accounting for all environments - * @param e A pointer to an ebgenv_t context. + * @param reserved Historic parameter, must be NULL. * @return ustate value */ -uint16_t ebg_env_getglobalstate(ebgenv_t *e); +uint16_t ebg_env_getglobalstate(void *reserved); /** @brief Set global ustate value, accounting for all environments * if state is set to zero and updating only current environment if -- 2.43.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 view this discussion visit https://groups.google.com/d/msgid/efibootguard-dev/45124943-65fd-4066-89a8-d35f678854fc%40siemens.com.
