diff mbox series

[RFC,v2,2/3] libubootenv: Forbid to give empty variable name to fw_setenv.

Message ID 20210706180018.342553-3-francis.laniel@amarulasolutions.com
State Accepted
Headers show
Series [RFC,v2,1/3] main: Check libuboot_set_env() result. | expand

Commit Message

Francis Laniel July 6, 2021, 6 p.m. UTC
Before this patch, it was possible to do the following:
fw_setenv '' foo
Which leads to having this in the environment:
=foo
Which in turns causes U-Boot to throw error when parsing environment.

Now, if the above command is given, an error code is returned and environment is
not modified.

Signed-off-by: Francis Laniel <francis.laniel@amarulasolutions.com>
Acked-by: Stefano Babic <sbabic@denx.de>
---
 src/uboot_env.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/src/uboot_env.c b/src/uboot_env.c
index 30c39eb..b97507a 100644
--- a/src/uboot_env.c
+++ b/src/uboot_env.c
@@ -1333,6 +1333,14 @@  int libuboot_set_env(struct uboot_ctx *ctx, const char *varname, const char *val
 	if (strchr(varname, '='))
 		return -EINVAL;
 
+	/*
+	 * Giving empty variable name will lead to having "=value" in U-Boot
+	 * environment which will lead to problem during load of it and U-Boot
+	 * will then load default environment.
+	 */
+	if (*varname == '\0')
+		return -EINVAL;
+
 	entry = __libuboot_get_env(envs, varname);
 	if (entry) {
 		if (libuboot_validate_flags(entry, value)) {