diff mbox series

[2/5] swupdate_vars: check namespace init worked

Message ID 20240705065434.3608030-3-dominique.martinet@atmark-techno.com
State Accepted
Headers show
Series misc fixes | expand

Commit Message

Dominique Martinet July 5, 2024, 6:54 a.m. UTC
if the fw_env config didn't contain the requested namespace (or config
was invalid) then libuboot_get_namespace() will fail and that will
segfault swupdate

This is an admin error so not a critical bug, but might as well
check and print an error.

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
 core/swupdate_vars.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Stefano Babic July 5, 2024, 12:09 p.m. UTC | #1
On 05.07.24 08:54, Dominique Martinet wrote:
> if the fw_env config didn't contain the requested namespace (or config
> was invalid) then libuboot_get_namespace() will fail and that will
> segfault swupdate
>
> This is an admin error so not a critical bug, but might as well
> check and print an error.
>
> Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
> ---
>   core/swupdate_vars.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/core/swupdate_vars.c b/core/swupdate_vars.c
> index f1e536a845be..081e6097e1e2 100644
> --- a/core/swupdate_vars.c
> +++ b/core/swupdate_vars.c
> @@ -47,6 +47,10 @@ int swupdate_vars_initialize(struct uboot_ctx **ctx, const char *namespace)
>   	}
>
>   	*ctx = libuboot_get_namespace(*ctx, namespace);
> +	if (!*ctx) {
> +		ERROR("Cannot get namespace %s from %s", namespace, get_fwenv_config());
> +		return -EINVAL;
> +	}
>
>   	if (libuboot_open(*ctx) < 0) {
>   		WARN("Cannot read environment, maybe still empty ?");


Thanks, I forget to check it when I added this code !

Acked-by: Stefano Babic <stefano.babic@swupdate.org>

Best regards,
Stefano
diff mbox series

Patch

diff --git a/core/swupdate_vars.c b/core/swupdate_vars.c
index f1e536a845be..081e6097e1e2 100644
--- a/core/swupdate_vars.c
+++ b/core/swupdate_vars.c
@@ -47,6 +47,10 @@  int swupdate_vars_initialize(struct uboot_ctx **ctx, const char *namespace)
 	}
 
 	*ctx = libuboot_get_namespace(*ctx, namespace);
+	if (!*ctx) {
+		ERROR("Cannot get namespace %s from %s", namespace, get_fwenv_config());
+		return -EINVAL;
+	}
 
 	if (libuboot_open(*ctx) < 0) {
 		WARN("Cannot read environment, maybe still empty ?");