Source-Changes-HG archive

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

[src/trunk]: src/bin/sh PR bin/51119 - don't leak FDs in unusual error cases....



details:   https://anonhg.NetBSD.org/src/rev/9206fda69b8f
branches:  trunk
changeset: 815245:9206fda69b8f
user:      kre <kre%NetBSD.org@localhost>
date:      Sat May 07 20:06:30 2016 +0000

description:
PR bin/51119 - don't leak FDs in unusual error cases.   OK christos@

diffstat:

 bin/sh/input.c |  12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (36 lines):

diff -r 07a11a5aa801 -r 9206fda69b8f bin/sh/input.c
--- a/bin/sh/input.c    Sat May 07 17:47:34 2016 +0000
+++ b/bin/sh/input.c    Sat May 07 20:06:30 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: input.c,v 1.49 2016/05/02 01:46:31 christos Exp $      */
+/*     $NetBSD: input.c,v 1.50 2016/05/07 20:06:30 kre Exp $   */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)input.c    8.3 (Berkeley) 6/9/95";
 #else
-__RCSID("$NetBSD: input.c,v 1.49 2016/05/02 01:46:31 christos Exp $");
+__RCSID("$NetBSD: input.c,v 1.50 2016/05/07 20:06:30 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -404,11 +404,15 @@
         */
        if (lseek(fd, 0, SEEK_SET) == 0) {
                if (read(fd, magic, 4) == 4) {
-                       if (memcmp(magic, "\177ELF", 4) == 0)
+                       if (memcmp(magic, "\177ELF", 4) == 0) {
+                               (void)close(fd);
                                error("Cannot execute ELF binary %s", fname);
+                       }
                }
-               if (lseek(fd, 0, SEEK_SET) != 0)
+               if (lseek(fd, 0, SEEK_SET) != 0) {
+                       (void)close(fd);
                        error("Cannot rewind the file %s", fname);
+               }
        }
 
        fd2 = to_upper_fd(fd);  /* closes fd, returns higher equiv */



Home | Main Index | Thread Index | Old Index