From: schwarze Date: Wed, 7 May 2014 21:20:06 +0000 (+0000) Subject: Repair the termination condition of a write(2) loop. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ca01651ad1a4d482c3eca2b36fed210c15c50f1d;p=openbsd 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 ; ok millert@. --- 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)