Module Name: src
Committed By: kre
Date: Sat Nov 4 07:26:35 UTC 2017
Modified Files:
src/lib/libc/stdio: fopen.c
Log Message:
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).
To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/fopen.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/stdio/fopen.c
diff -u src/lib/libc/stdio/fopen.c:1.15 src/lib/libc/stdio/fopen.c:1.16
--- src/lib/libc/stdio/fopen.c:1.15 Thu Mar 15 18:22:30 2012
+++ src/lib/libc/stdio/fopen.c Sat Nov 4 07:26:35 2017
@@ -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;
}