From ca01651ad1a4d482c3eca2b36fed210c15c50f1d Mon Sep 17 00:00:00 2001 From: schwarze Date: Wed, 7 May 2014 21:20:06 +0000 Subject: [PATCH] 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@. --- usr.sbin/vipw/vipw.c | 4 ++-- 1 file 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) -- 2.20.1