Source-Changes-HG archive

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

[src/trunk]: src/sbin/fsck_lfs Check some error conditions that would otherwi...



details:   https://anonhg.NetBSD.org/src/rev/c3bbf16aa2dd
branches:  trunk
changeset: 581078:c3bbf16aa2dd
user:      perseant <perseant%NetBSD.org@localhost>
date:      Mon May 23 22:17:20 2005 +0000

description:
Check some error conditions that would otherwise cause fsck_lfs to dump core.
Pointed out by Pavel Cahyna in a follow-on to PR #29151.

diffstat:

 sbin/fsck_lfs/lfs.c   |   4 ++--
 sbin/fsck_lfs/setup.c |  12 +++++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diffs (46 lines):

diff -r 81866c549c33 -r c3bbf16aa2dd sbin/fsck_lfs/lfs.c
--- a/sbin/fsck_lfs/lfs.c       Mon May 23 22:01:11 2005 +0000
+++ b/sbin/fsck_lfs/lfs.c       Mon May 23 22:17:20 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs.c,v 1.12 2005/04/23 20:21:03 perseant Exp $ */
+/* $NetBSD: lfs.c,v 1.13 2005/05/23 22:17:20 perseant Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -424,7 +424,7 @@
        LFS_IENTRY(ifp, fs, ino, bp);
        daddr = ifp->if_daddr;
        brelse(bp);
-       if (daddr == 0)
+       if (daddr <= 0 || dtosn(fs, daddr) >= fs->lfs_nseg)
                return NULL;
        return lfs_raw_vget(fs, ino, fs->lfs_ivnode->v_fd, daddr);
 }
diff -r 81866c549c33 -r c3bbf16aa2dd sbin/fsck_lfs/setup.c
--- a/sbin/fsck_lfs/setup.c     Mon May 23 22:01:11 2005 +0000
+++ b/sbin/fsck_lfs/setup.c     Mon May 23 22:17:20 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: setup.c,v 1.21 2005/04/14 21:15:59 perseant Exp $ */
+/* $NetBSD: setup.c,v 1.22 2005/05/23 22:17:20 perseant Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -322,8 +322,18 @@
         * allocate and initialize the necessary maps
         */
        din_table = (ufs_daddr_t *) malloc(maxino * sizeof(*din_table));
+       if (din_table == NULL) {
+               printf("cannot alloc %u bytes for din_table\n",
+                   (unsigned) maxino * sizeof(*din_table));
+               goto badsblabel;
+       }
        memset(din_table, 0, maxino * sizeof(*din_table));
        seg_table = (SEGUSE *) malloc(fs->lfs_nseg * sizeof(SEGUSE));
+       if (seg_table == NULL) {
+               printf("cannot alloc %u bytes for seg_table\n",
+                   (unsigned) fs->lfs_nseg * sizeof(SEGUSE));
+               goto badsblabel;
+       }
        memset(seg_table, 0, fs->lfs_nseg * sizeof(SEGUSE));
        /* Get segment flags */
        for (i = 0; i < fs->lfs_nseg; i++) {



Home | Main Index | Thread Index | Old Index