Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdio Avoid losing a fd (ie: close it) in the (ever...



details:   https://anonhg.NetBSD.org/src/rev/46f78f55382c
branches:  trunk
changeset: 357280:46f78f55382c
user:      kre <kre%NetBSD.org@localhost>
date:      Sat Nov 04 07:26:35 2017 +0000

description:
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:

 lib/libc/stdio/fopen.c |  5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diffs (26 lines):

diff -r 19e0b1864686 -r 46f78f55382c lib/libc/stdio/fopen.c
--- a/lib/libc/stdio/fopen.c    Sat Nov 04 07:04:01 2017 +0000
+++ b/lib/libc/stdio/fopen.c    Sat Nov 04 07:26:35 2017 +0000
@@ -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 @@
         * open. (We treat the short as unsigned, and special-case -1).
         */
        if (f >= USHRT_MAX) {
+               (void)close(f);
                errno = EMFILE;
                goto release;
        }



Home | Main Index | Thread Index | Old Index