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:
parent
9210db64a6
commit
12235ef107
|
@ -94,7 +94,7 @@ static void copyfile(int from, int to)
|
||||||
char buf[8 * 1024];
|
char buf[8 * 1024];
|
||||||
|
|
||||||
while ((nr = read(from, buf, sizeof(buf))) > 0)
|
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)
|
if ((nw = write(to, buf + off, nr)) < 0)
|
||||||
pw_error(tmp_file, 1, 1);
|
pw_error(tmp_file, 1, 1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue