From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] nvvar: Fix creation without value
Date: Fri, 7 Apr 2017 08:30:38 +0200 [thread overview]
Message-ID: <20170407063038.2703-1-s.hauer@pengutronix.de> (raw)
When a new nvvar is added without a value we want to get the value
from the corresponding globalvar. We do this by using nv_set which
ends up freeing the exact string that we passed into nv_set as
value. This results in a corrupt value. Fix this by assigning a
value manually without calling nv_set.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/globalvar.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/common/globalvar.c b/common/globalvar.c
index 52808f8852..ab573cc68d 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -233,10 +233,16 @@ static int __nvvar_add(const char *name, const char *value)
if (ret && ret != -EEXIST)
return ret;
- if (!value)
- value = dev_get_param(&global_device, name);
+ if (value)
+ return nv_set(&nv_device, p, value);
+
+ value = dev_get_param(&global_device, name);
+ if (value) {
+ free(p->value);
+ p->value = xstrdup(value);
+ }
- return nv_set(&nv_device, p, value);
+ return 0;
}
int nvvar_add(const char *name, const char *value)
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
reply other threads:[~2017-04-07 6:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170407063038.2703-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox