If the number of inodes per block is zero, bail instead of using

uninitialized stack trash as a dinode pointer. Fixes PR 51409 where
"dumplfs /dev/zero" receives SIGSEGV.
This commit is contained in:
dholland 2016-08-12 08:22:13 +00:00
parent 7346e185f5
commit a8308178f6
1 changed files with 9 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: dumplfs.c,v 1.62 2016/06/15 14:07:54 riastradh Exp $ */
/* $NetBSD: dumplfs.c,v 1.63 2016/08/12 08:22:13 dholland Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993\
#if 0
static char sccsid[] = "@(#)dumplfs.c 8.5 (Berkeley) 5/24/95";
#else
__RCSID("$NetBSD: dumplfs.c,v 1.62 2016/06/15 14:07:54 riastradh Exp $");
__RCSID("$NetBSD: dumplfs.c,v 1.63 2016/08/12 08:22:13 dholland Exp $");
#endif
#endif /* not lint */
@ -336,12 +336,19 @@ dump_ifile(int fd, struct lfs *lfsp, int do_ientries, int do_segentries, daddr_t
err(1, "malloc");
get(fd, fsbtobyte(lfsp, addr), dpage, psize);
dip = NULL;
for (i = LFS_INOPB(lfsp); i-- > 0; ) {
dip = DINO_IN_BLOCK(lfsp, dpage, i);
if (lfs_dino_getinumber(lfsp, dip) == LFS_IFILE_INUM)
break;
}
/* just in case */
if (dip == NULL) {
warnx("this volume apparently has zero inodes per block");
return;
}
if (lfs_dino_getinumber(lfsp, dip) != LFS_IFILE_INUM) {
warnx("unable to locate ifile inode at disk address 0x%jx",
(uintmax_t)addr);