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 <chandrababu.pigilam@digi.com>
Signed-off-by: Hector Palacios <hector.palacios@digi.com>

https://onedigi.atlassian.net/browse/DEL-7645
(cherry picked from commit 8a4484bbd6)
This commit is contained in:
Hector Palacios 2021-08-25 11:45:40 +02:00
parent 225e6cafb5
commit 53759cd29c
1 changed files with 5 additions and 1 deletions

View File

@ -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;