[PATCH 1/3] defaultenv: skip non-existent dirs in defaultenv_append_runtime_directory
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Nov 24 09:59:40 PST 2025
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 at pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum at 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
More information about the barebox
mailing list