diff mbox series

BUG: fix segfault when CONFIG_UBOOT_NEWAPI is set

Message ID 20190314144217.7321-1-sbabic@denx.de
State Accepted
Headers show
Series BUG: fix segfault when CONFIG_UBOOT_NEWAPI is set | expand

Commit Message

Stefano Babic March 14, 2019, 2:42 p.m. UTC
A wrong initialization of the library caused a crash because the context
pointer is Null.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 bootloader/uboot.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/bootloader/uboot.c b/bootloader/uboot.c
index 4fb8844..e57b8bd 100644
--- a/bootloader/uboot.c
+++ b/bootloader/uboot.c
@@ -130,19 +130,19 @@  int bootloader_apply_list(const char *filename)
 #define CONFIG_UBOOT_DEFAULTENV	"/etc/u-boot-initial-env"
 #endif
 
-static int bootloader_initialize(struct uboot_ctx *ctx)
+static int bootloader_initialize(struct uboot_ctx **ctx)
 {
-	if (libuboot_initialize(&ctx, NULL) < 0) {
+	if (libuboot_initialize(ctx, NULL) < 0) {
 		ERROR("Error: environment not initialized");
 		return -ENODEV;
 	}
-	if (libuboot_read_config(ctx, CONFIG_UBOOT_FWENV) < 0) {
+	if (libuboot_read_config(*ctx, CONFIG_UBOOT_FWENV) < 0) {
 		ERROR("Configuration file %s wrong or corrupted", CONFIG_UBOOT_FWENV);
 		return -EINVAL;
 	}
-	if (libuboot_open(ctx) < 0) {
+	if (libuboot_open(*ctx) < 0) {
 		ERROR("Cannot read environment, using default\n");
-		libuboot_load_file(ctx, CONFIG_UBOOT_DEFAULTENV);
+		libuboot_load_file(*ctx, CONFIG_UBOOT_DEFAULTENV);
 	}
 
 	return 0;
@@ -153,7 +153,7 @@  int bootloader_env_set(const char *name, const char *value)
 	int ret;
 	struct uboot_ctx *ctx = NULL;
 
-	ret = bootloader_initialize(ctx);
+	ret = bootloader_initialize(&ctx);
 	if (!ret) {
 		libuboot_set_env(ctx, name, value);
 		ret = libuboot_env_store(ctx);
@@ -167,7 +167,7 @@  int bootloader_env_set(const char *name, const char *value)
 
 int bootloader_env_unset(const char *name)
 {
-	return bootloader_env_set(name, "");
+	return bootloader_env_set(name, NULL);
 }
 
 
@@ -176,7 +176,7 @@  int bootloader_apply_list(const char *filename)
 	int ret;
 	struct uboot_ctx *ctx = NULL;
 
-	ret = bootloader_initialize(ctx);
+	ret = bootloader_initialize(&ctx);
 	if (!ret) {
 		libuboot_load_file(ctx, filename);
 		ret = libuboot_env_store(ctx);
@@ -194,7 +194,7 @@  char *bootloader_env_get(const char *name)
 	struct uboot_ctx *ctx = NULL;
 	char *value = NULL;
 
-	ret = bootloader_initialize(ctx);
+	ret = bootloader_initialize(&ctx);
 	if (!ret) {
 		value = libuboot_get_env(ctx, name);
 	}