[PATCH 12/19] lib: make_directory: return -ENOMEM on allocation failure

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Jun 12 06:02:33 PDT 2023


mkdir calls strdup on the dir that's passed in, but doesn't account for
allocation failure. Have it return -ENOMEM in that case.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 lib/make_directory.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/make_directory.c b/lib/make_directory.c
index 7db93ded8817..59ac87e6bfdf 100644
--- a/lib/make_directory.c
+++ b/lib/make_directory.c
@@ -19,6 +19,9 @@ STATIC int make_directory(const char *dir)
 	char c;
 	int ret = 0;
 
+	if (!s)
+		return -ENOMEM;
+
 	do {
 		c = 0;
 
-- 
2.39.2




More information about the barebox mailing list