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