mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/2] environment: Allow default env path to be NULL
Date: Fri, 21 Sep 2018 14:29:54 +0200	[thread overview]
Message-ID: <20180921122955.9513-1-s.hauer@pengutronix.de> (raw)

Several places assume that the default environment path cannot be NULL.
Allow NULL here without crashing.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/loadenv.c   | 4 ++++
 common/environment.c | 9 +++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/commands/loadenv.c b/commands/loadenv.c
index 6469affadb..bf01072c42 100644
--- a/commands/loadenv.c
+++ b/commands/loadenv.c
@@ -61,6 +61,10 @@ static int do_loadenv(int argc, char *argv[])
 
 	if (argc - optind < 1) {
 		filename = default_environment_path_get();
+		if (!filename) {
+			printf("Default environment path not set\n");
+			return 1;
+		}
 	} else {
 		/*
 		 * /dev/defaultenv use to contain the defaultenvironment.
diff --git a/common/environment.c b/common/environment.c
index 0edf34b661..56a030eda0 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -256,9 +256,12 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 	struct action_data data = {};
 	void *buf = NULL, *wbuf;
 	struct envfs_entry *env;
+	const char *defenv_path = default_environment_path_get();
 
 	if (!filename)
-		filename = default_environment_path_get();
+		filename = defenv_path;
+	if (!filename)
+		return -ENOENT;
 
 	if (!dirname)
 		dirname = "/env";
@@ -365,7 +368,7 @@ int envfs_save(const char *filename, const char *dirname, unsigned flags)
 	ret = 0;
 
 #ifdef CONFIG_NVVAR
-	if (!strcmp(filename, default_environment_path_get()))
+	if (defenv_path && !strcmp(filename, defenv_path))
 	    nv_var_set_clean();
 #endif
 out:
@@ -558,6 +561,8 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
 
 	if (!filename)
 		filename = default_environment_path_get();
+	if (!filename)
+		return -ENOENT;
 
 	if (!dir)
 		dir = "/env";
-- 
2.19.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2018-09-21 12:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-21 12:29 Sascha Hauer [this message]
2018-09-21 12:29 ` [PATCH 2/2] environment: Do not use environment when overlapping with other partitions Sascha Hauer
2018-09-24 13:23   ` Andrey Smirnov
2018-09-26  6:55     ` Sascha Hauer

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=20180921122955.9513-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