[PATCH 3/4] commands: nv: pass empty string for nv

Ahmad Fatoum ahmad at a3f.at
Thu Nov 26 13:31:53 EST 2020


Setting a variable via the nv command results in the call chain
nvar_add() -> nv_save() -> __nv_save().

__nv_save isn't supposed to be called with val=NULL argument however:

	dprintf(fd, "%s", val);

Avoid this from happening by translating NULL into the empty string.
This aligns nv with the behavior of hush and setenv (but not global,
this will need to be looked at separately).

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 commands/nv.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/commands/nv.c b/commands/nv.c
index fa865811dce2..a1cff08ee463 100644
--- a/commands/nv.c
+++ b/commands/nv.c
@@ -59,6 +59,8 @@ static int do_nv(int argc, char *argv[])
 		if (value) {
 			*value = 0;
 			value++;
+		} else {
+			value = "";
 		}
 
 		if (do_remove) {
-- 
2.28.0




More information about the barebox mailing list