diff mbox series

Fix coverity #292128

Message ID 20200416191401.10717-4-sbabic@denx.de
State Accepted
Headers show
Series Fix coverity #292128 | expand

Commit Message

Stefano Babic April 16, 2020, 7:14 p.m. UTC
Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/swupdate.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/core/swupdate.c b/core/swupdate.c
index 48d9f49..c749782 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -447,9 +447,16 @@  static int _remove_directory_cb(const char *fpath, const struct stat *sb,
 
 static int remove_directory(const char* path)
 {
-	char* dpath = alloca(strlen(get_tmpdir())+strlen(path)+1);
-	sprintf(dpath, "%s%s", get_tmpdir(), path);
-	return nftw(dpath, _remove_directory_cb, 64, FTW_DEPTH | FTW_PHYS);
+	char* dpath;
+	int ret;
+	if (asprintf(&dpath, "%s%s", get_tmpdir(), path) ==
+		ENOMEM_ASPRINTF) {
+		ERROR("OOM: Directory %s not removed", path);
+		return -ENOMEM;
+	}
+	ret = nftw(dpath, _remove_directory_cb, 64, FTW_DEPTH | FTW_PHYS);
+	free(dpath);
+	return ret;
 }
 #endif