Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/systat - avoid coredump by returning NULL when read ...



details:   https://anonhg.NetBSD.org/src/rev/0b970dfaf009
branches:  trunk
changeset: 556074:0b970dfaf009
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Dec 07 07:28:05 2003 +0000

description:
- avoid coredump by returning NULL when read fails and don't keep following
  the list.
- avoid zerodivide.
XXX: still does not work, but at least it does not core-dump.

diffstat:

 usr.bin/systat/bufcache.c |  17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diffs (68 lines):

diff -r 39b5541f25c3 -r 0b970dfaf009 usr.bin/systat/bufcache.c
--- a/usr.bin/systat/bufcache.c Sun Dec 07 07:27:09 2003 +0000
+++ b/usr.bin/systat/bufcache.c Sun Dec 07 07:28:05 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bufcache.c,v 1.13 2003/02/24 10:10:00 dsl Exp $        */
+/*     $NetBSD: bufcache.c,v 1.14 2003/12/07 07:28:05 christos Exp $   */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: bufcache.c,v 1.13 2003/02/24 10:10:00 dsl Exp $");
+__RCSID("$NetBSD: bufcache.c,v 1.14 2003/12/07 07:28:05 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -201,7 +201,7 @@
            "%-20s    %6d %3d    %8ld %3ld    %8ld %3ld     %3ld",
            "Total:", tbuf, (100 * tbuf) / nbuf,
            tvalid, (100 * tvalid) / bufkb,
-           tsize, (100 * tsize) / bufkb, (100 * tvalid) / tsize); 
+           tsize, (100 * tsize) / bufkb, tsize ? (100 * tvalid) / tsize : 0); 
 }
 
 int
@@ -278,8 +278,7 @@
                                if (bp->b_vp != NULL) {
                                        vn = vc_lookup(bp->b_vp);
                                        if (vn == NULL)
-                                               errx(1,
-                                                   "vc_lookup returns NULL!\n");
+                                               break;
                                        if (vn->v_mount != NULL)
                                                mt = ml_lookup(vn->v_mount,
                                                    bp->b_bufsize,
@@ -337,10 +336,10 @@
 vc_lookup(struct vnode *vaddr)
 {
        struct vnode *ret;
-       int i, oldest, match;
+       size_t i, oldest;
 
        ret = NULL;
-       oldest = match = 0;
+       oldest = 0;
        for (i = 0; i < VCACHE_SIZE || vcache[i].vc_addr == NULL; i++) {
                vcache[i].vc_age++;
                if (vcache[i].vc_addr == NULL)
@@ -349,7 +348,6 @@
                        oldest = i;
                if (vcache[i].vc_addr == vaddr) {
                        vcache[i].vc_age = 0;
-                       match = i;
                        ret = &vcache[i].vc_node;
                }
        }
@@ -363,7 +361,8 @@
                i = oldest;
 
        /* Read in new vnode and reset age counter. */
-       KREAD(vaddr, &vcache[i].vc_node, sizeof(struct vnode));
+       if (KREAD(vaddr, &vcache[i].vc_node, sizeof(struct vnode)) == 0)
+               return NULL;
        vcache[i].vc_addr = vaddr;
        vcache[i].vc_age = 0;
 



Home | Main Index | Thread Index | Old Index