Module Name:    src
Committed By:   joerg
Date:           Sun Jan 10 16:40:01 UTC 2010

Modified Files:
        src/usr.sbin/pwd_mkdb: pwd_mkdb.c

Log Message:
Don't leak two file descriptors in cp(). From Igor Zinovik.
Explicitly check the close for errors and bail out if needed.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/usr.sbin/pwd_mkdb/pwd_mkdb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/pwd_mkdb/pwd_mkdb.c
diff -u src/usr.sbin/pwd_mkdb/pwd_mkdb.c:1.49 src/usr.sbin/pwd_mkdb/pwd_mkdb.c:1.50
--- src/usr.sbin/pwd_mkdb/pwd_mkdb.c:1.49	Fri Nov  6 15:00:31 2009
+++ src/usr.sbin/pwd_mkdb/pwd_mkdb.c	Sun Jan 10 16:40:00 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: pwd_mkdb.c,v 1.49 2009/11/06 15:00:31 joerg Exp $	*/
+/*	$NetBSD: pwd_mkdb.c,v 1.50 2010/01/10 16:40:00 joerg Exp $	*/
 
 /*
  * Copyright (c) 2000, 2009 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  The NetBSD Foundation, Inc.  All rights reserved.\
   Copyright (c) 1991, 1993, 1994\
  The Regents of the University of California.  All rights reserved.");
-__RCSID("$NetBSD: pwd_mkdb.c,v 1.49 2009/11/06 15:00:31 joerg Exp $");
+__RCSID("$NetBSD: pwd_mkdb.c,v 1.50 2010/01/10 16:40:00 joerg Exp $");
 #endif /* not lint */
 
 #if HAVE_NBTOOL_CONFIG_H
@@ -649,20 +649,22 @@
 		error(to);
 	while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) {
 		wcount = write(to_fd, buf, (size_t)rcount);
-		if (rcount != wcount || wcount == -1) {
-			sverrno = errno;
-			(void)snprintf(buf, sizeof(buf), "%s to %s", from, to);
-			errno = sverrno;
-			error(buf);
-		}
+		if (rcount != wcount || wcount == -1)
+			goto on_error;
 	}
 
-	if (rcount < 0) {
-		sverrno = errno;
-		(void)snprintf(buf, sizeof(buf), "%s to %s", from, to);
-		errno = sverrno;
-		error(buf);
-	}
+	if (rcount < 0)
+		goto on_error;
+	close(from_fd);
+	if (close(to_fd))
+		goto on_error
+	return;
+
+on_error:
+	sverrno = errno;
+	(void)snprintf(buf, sizeof(buf), "%s to %s", from, to);
+	errno = sverrno;
+	error(buf);
 }
 
 void

Reply via email to