From 4069e159fc46c98191a9d26a0e6b9ff097c40996 Mon Sep 17 00:00:00 2001 From: Egor Chelak Date: Thu, 29 Oct 2020 19:06:13 +0200 Subject: [PATCH] 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 --- login-utils/vipw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/login-utils/vipw.c b/login-utils/vipw.c index a071b639dd..38953b7f59 100644 --- a/login-utils/vipw.c +++ b/login-utils/vipw.c @@ -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); -- 2.47.2