Source-Changes-HG archive

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

[src/trunk]: src/sbin/badsect don't use the result of a readdir() after close...



details:   https://anonhg.NetBSD.org/src/rev/52dad9ad0fb4
branches:  trunk
changeset: 475054:52dad9ad0fb4
user:      drochner <drochner%NetBSD.org@localhost>
date:      Fri Jul 30 15:56:58 1999 +0000

description:
don't use the result of a readdir() after closedir(), from
Christian Groessler per PR bin/8107

diffstat:

 sbin/badsect/badsect.c |  12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (42 lines):

diff -r 932ce81f85bd -r 52dad9ad0fb4 sbin/badsect/badsect.c
--- a/sbin/badsect/badsect.c    Fri Jul 30 14:59:10 1999 +0000
+++ b/sbin/badsect/badsect.c    Fri Jul 30 15:56:58 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: badsect.c,v 1.16 1998/08/25 19:18:12 ross Exp $        */
+/*     $NetBSD: badsect.c,v 1.17 1999/07/30 15:56:58 drochner Exp $    */
 
 /*
  * Copyright (c) 1981, 1983, 1993
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)badsect.c  8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: badsect.c,v 1.16 1998/08/25 19:18:12 ross Exp $");
+__RCSID("$NetBSD: badsect.c,v 1.17 1999/07/30 15:56:58 drochner Exp $");
 #endif
 #endif /* not lint */
 
@@ -132,10 +132,11 @@
                    S_ISBLK(devstat.st_mode))
                        break;
        }
-       closedir(dirp);
-       if (dp == NULL)
+       if (dp == NULL) {
+               closedir(dirp);
                errx(1, "Cannot find dev 0%o corresponding to %s", 
                    stbuf.st_rdev, argv[1]);
+       }
 
        /*
         * The filesystem is mounted; use the character device instead.
@@ -143,6 +144,9 @@
         * the character device.
         */
        (void) snprintf(name, sizeof(name), "%sr%s", _PATH_DEV, dp->d_name);
+
+       closedir(dirp); /* now *dp is invalid */
+
        if ((fsi = open(name, O_RDONLY)) == -1)
                err(1, "Cannot open `%s'", argv[1]);
 



Home | Main Index | Thread Index | Old Index