From 8a4484bbd69d43fcea36fc73322f5a41e740565c Mon Sep 17 00:00:00 2001 From: Hector Palacios Date: Wed, 25 Aug 2021 11:45:40 +0200 Subject: [PATCH] recovery: check variable returned by uboot_getenv() is not NULL The use of this function, which is a wrapper over libuboot_get_env(), requires checking if the returned string is NULL. Manipulations of such string without checking whether it's NULL may lead to segfault errors. This was seen during firmware update on a device that didn't have the 'dualboot' variable set. Reported-by: Chandrababu Pigilam Signed-off-by: Hector Palacios https://onedigi.atlassian.net/browse/DEL-7645 --- .../recovery/recovery-utils/recovery-utils/lib/recovery.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/lib/recovery.c b/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/lib/recovery.c index 6781b8930..d053a932c 100644 --- a/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/lib/recovery.c +++ b/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/lib/recovery.c @@ -439,7 +439,7 @@ static int parse_nand_partition_info(char **parts, char **encrypted, unsigned ch /* Parse mtdparts for all partition info */ ret = uboot_getenv("mtdparts", &var); - if (ret) { + if (ret || !var) { fprintf(stderr, "Error: getenv 'mtdparts'\n"); return ret; } @@ -978,6 +978,10 @@ int is_dualboot_enabled (void) return 0; } + /* Consider dualboot not enabled if variable doesn't exist */ + if (!var) + return 0; + /* Is dualboot enabled */ if (!strcmp(var, "no")) ret = 0;