mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] defaultenv: skip non-existent dirs in defaultenv_append_runtime_directory
@ 2025-11-24 17:59 Ahmad Fatoum
  2025-11-24 17:59 ` [PATCH 2/3] defaultenv: don't abort defaultenv_load silently on error Ahmad Fatoum
  2025-11-24 17:59 ` [PATCH 3/3] defaultenv: add base and external defaultenv in pure_initcall Ahmad Fatoum
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2025-11-24 17:59 UTC (permalink / raw)
  To: barebox; +Cc: Jan Lübbe, Ahmad Fatoum

QEMU fw_cfg file system driver is the sole user of
defaultenv_append_runtime_directory() and it passes a path that's not
necessarily available.

When that happens, this is not noticed until the loop in defaultenv_load()
aborts early with an -ENOENT preventing load of an external environment.

Fix this as well as further issues of this sort by not adding directories
that don't exist at the time defaultenv_append_runtime_directory() is
called.

Fixes: 31dfb561d1a4 ("fs: qemu_fw_cfg: support populating environment via QEMU fw_cfg")
Reported-by: Jan Lübbe <j.luebbe@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 defaultenv/defaultenv.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/defaultenv/defaultenv.c b/defaultenv/defaultenv.c
index d6cca466a683..652fda05027a 100644
--- a/defaultenv/defaultenv.c
+++ b/defaultenv/defaultenv.c
@@ -20,6 +20,7 @@
 #include <init.h>
 #include <libfile.h>
 #include <asm/unaligned.h>
+#include <fs.h>
 #include "barebox_default_env.h"
 
 static LIST_HEAD(defaultenv_list);
@@ -100,6 +101,10 @@ void defaultenv_append(void *buf, unsigned int size, const char *name)
 void defaultenv_append_runtime_directory(const char *srcdir)
 {
 	struct defaultenv *df;
+	struct stat s;
+
+	if (stat(srcdir, &s) || !S_ISDIR(s.st_mode))
+		return;
 
 	defaultenv_add_base();
 
-- 
2.47.3




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-24 18:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-24 17:59 [PATCH 1/3] defaultenv: skip non-existent dirs in defaultenv_append_runtime_directory Ahmad Fatoum
2025-11-24 17:59 ` [PATCH 2/3] defaultenv: don't abort defaultenv_load silently on error Ahmad Fatoum
2025-11-24 17:59 ` [PATCH 3/3] defaultenv: add base and external defaultenv in pure_initcall Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox