summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2014-05-07 21:20:07 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2014-05-07 21:20:07 +0000
commit0443570fcc0e6e1bb321c6e9d28a525f098c0f87 (patch)
tree820c15a2cf7f7a0b30d17915dea65832a746cef2
parentc262d59aa1c5a3e89984db2c67c61f02f02517d7 (diff)
Repair the termination condition of a write(2) loop.
Since _PATH_MASTERPASSWD_LOCK is on a local file system in any sane setup and written to in blocking mode, i don't see how write(2) could return before having written everything, so this maybe wasn't an actual bug, but it should be repaired anyway, if only for clarity and extra safety. From Ben Cornett <ben at lantern dot is>; ok millert@.
-rw-r--r--usr.sbin/vipw/vipw.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/usr.sbin/vipw/vipw.c b/usr.sbin/vipw/vipw.c
index d75d29411a3..b6700a5a982 100644
--- a/usr.sbin/vipw/vipw.c
+++ b/usr.sbin/vipw/vipw.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vipw.c,v 1.16 2011/08/19 20:53:36 millert Exp $ */
+/* $OpenBSD: vipw.c,v 1.17 2014/05/07 21:20:06 schwarze Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -100,7 +100,7 @@ copyfile(int from, int to, struct stat *sb)
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)