]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
vipw: fix short write handling in copyfile
authorEgor Chelak <egor.chelak@gmail.com>
Thu, 29 Oct 2020 17:06:13 +0000 (19:06 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Nov 2020 11:33:09 +0000 (12:33 +0100)
Since `off` and `nr` approach each other, the for-loop ends prematurely
when at least half of the buffer was written.  I think under certain
conditions this could cause the copy to be incomplete.

Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
login-utils/vipw.c

index a071b639dd03e1926c07405941de64479bd62a8e..38953b7f5923980d01e33e489a1caef494b78c54 100644 (file)
@@ -94,7 +94,7 @@ static void copyfile(int from, int to)
        char buf[8 * 1024];
 
        while ((nr = read(from, buf, sizeof(buf))) > 0)
-               for (off = 0; off < nr; nr -= nw, off += nw)
+               for (off = 0; nr > 0; nr -= nw, off += nw)
                        if ((nw = write(to, buf + off, nr)) < 0)
                                pw_error(tmp_file, 1, 1);