vipw: fix short write handling in copyfile

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>
This commit is contained in:
Egor Chelak 2020-10-29 19:06:13 +02:00
parent 9210db64a6
commit 12235ef107
1 changed files with 1 additions and 1 deletions

View 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);