Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/pwd_mkdb Don't leak two file descriptors in cp(). F...
details: https://anonhg.NetBSD.org/src/rev/3e955548a202
branches: trunk
changeset: 750682:3e955548a202
user: joerg <joerg%NetBSD.org@localhost>
date: Sun Jan 10 16:40:00 2010 +0000
description:
Don't leak two file descriptors in cp(). From Igor Zinovik.
Explicitly check the close for errors and bail out if needed.
diffstat:
usr.sbin/pwd_mkdb/pwd_mkdb.c | 30 ++++++++++++++++--------------
1 files changed, 16 insertions(+), 14 deletions(-)
diffs (53 lines):
diff -r d845225fa3b1 -r 3e955548a202 usr.sbin/pwd_mkdb/pwd_mkdb.c
--- a/usr.sbin/pwd_mkdb/pwd_mkdb.c Sun Jan 10 16:39:10 2010 +0000
+++ b/usr.sbin/pwd_mkdb/pwd_mkdb.c Sun Jan 10 16:40:00 2010 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index