summaryrefslogtreecommitdiff
path: root/lib/libc/stdio
diff options
context:
space:
mode:
authorkre <kre@NetBSD.org>2017-11-04 07:26:35 +0000
committerkre <kre@NetBSD.org>2017-11-04 07:26:35 +0000
commit93856cb4e6038e94db9df9ff2fa74d574f39812d (patch)
tree24a120c9d4e2c549e0a92ec351b59d4d59e637c4 /lib/libc/stdio
parentc5da5570c442cb80821c466cd1c104b9a4e91fbc (diff)
Avoid losing a fd (ie: close it) in the (ever so likely) case that the
fd exceeds the limits of what can be stored in a FILE (65535).
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r--lib/libc/stdio/fopen.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c
index c1792ebd8f0..96b2c0566b1 100644
--- a/lib/libc/stdio/fopen.c
+++ b/lib/libc/stdio/fopen.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fopen.c,v 1.15 2012/03/15 18:22:30 christos Exp $ */
+/* $NetBSD: fopen.c,v 1.16 2017/11/04 07:26:35 kre Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: fopen.c,v 1.15 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: fopen.c,v 1.16 2017/11/04 07:26:35 kre Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -88,6 +88,7 @@ fopen(const char *file, const char *mode)
* open. (We treat the short as unsigned, and special-case -1).
*/
if (f >= USHRT_MAX) {
+ (void)close(f);
errno = EMFILE;
goto release;
}