diff mbox series

[2/2] Drop filename length limit in CPIO extraction

Message ID 1513935659-8075-2-git-send-email-sbabic@denx.de
State Accepted
Headers show
Series [1/2] Move the define ENOMEM_ASPRINTF global | expand

Commit Message

Stefano Babic Dec. 22, 2017, 9:40 a.m. UTC
Signed-off-by: Stefano Babic <sbabic@denx.de>
Reported-by: Richard Alled <richard_allen@keysight.com>
---
 corelib/installer.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/corelib/installer.c b/corelib/installer.c
index c63de49..4890e83 100644
--- a/corelib/installer.c
+++ b/corelib/installer.c
@@ -252,7 +252,7 @@  int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
 {
 	int ret;
 	struct img_type *img;
-	char filename[64];
+	char *filename;
 	struct filehdr fdh;
 	struct stat buf;
 	const char* TMPDIR = get_tmpdir();
@@ -295,8 +295,8 @@  int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
 			continue;
 
 		if (!fromfile) {
-			if (snprintf(filename, sizeof(filename), "%s%s",
-				     TMPDIR, img->fname) >= (int)sizeof(filename)) {
+		    if (asprintf(&filename, "%s%s", TMPDIR, img->fname) ==
+				ENOMEM_ASPRINTF) {
 				ERROR("Path too long: %s%s", TMPDIR, img->fname);
 				return -1;
 			}
@@ -304,11 +304,13 @@  int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
 			ret = stat(filename, &buf);
 			if (ret) {
 				TRACE("%s not found or wrong", filename);
+				free(filename);
 				return -1;
 			}
 			img->size = buf.st_size;
 
 			img->fdin = open(filename, O_RDONLY);
+			free(filename);
 			if (img->fdin < 0) {
 				ERROR("Image %s cannot be opened",
 				img->fname);