The following corrects the termination condition on the write
loop in copyfile.
Index: usr.sbin/vipw/vipw.c
===================================================================
RCS file: /cvsroot/OpenBSD/src/usr.sbin/vipw/vipw.c,v
retrieving revision 1.16
diff -u -p -r1.16 vipw.c
--- usr.sbin/vipw/vipw.c 19 Aug 2011 20:53:36 -0000 1.16
+++ usr.sbin/vipw/vipw.c 22 Apr 2014 01:17:20 -0000
@@ -100,7 +100,7 @@ copyfile(int from, int to, struct stat *
if (fstat(from, sb) == -1)
pw_error(_PATH_MASTERPASSWD, 1, 1);
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(_PATH_MASTERPASSWD_LOCK, 1, 1);
if (nr < 0)