[PATCH 10/11] libfile: copy_file: Fix calling discard_range

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



discard range is called with unitialized size argument. Call it after
stat() on the source filedescriptor. Also there's no point in continuing
when stat() on the source filedescriptor fails, so bail out in this
case.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 lib/libfile.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/libfile.c b/lib/libfile.c
index b4d87b624a..9de938b2d3 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -364,14 +364,15 @@ int copy_file(const char *src, const char *dst, int verbose)
 		goto out;
 	}
 
-	discard_range(dstfd, srcstat.st_size, 0);
+	ret = stat(src, &srcstat);
+	if (ret)
+		goto out;
 
-	if (verbose) {
-		if (stat(src, &srcstat) < 0)
-			srcstat.st_size = 0;
+	if (srcstat.st_size != FILESIZE_MAX)
+		discard_range(dstfd, srcstat.st_size, 0);
 
+	if (verbose)
 		init_progression_bar(srcstat.st_size);
-	}
 
 	while (1) {
 		r = read(srcfd, rw_buf, RW_BUF_SIZE);
-- 
2.27.0


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux