Module Name: src Committed By: mlelstv Date: Fri Mar 27 11:13:57 UTC 2020
Modified Files: src/sys/kern: subr_disk.c Log Message: Avoid division by zero if label isn't valid. To generate a diff of this commit: cvs rdiff -u -r1.129 -r1.130 src/sys/kern/subr_disk.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/subr_disk.c diff -u src/sys/kern/subr_disk.c:1.129 src/sys/kern/subr_disk.c:1.130 --- src/sys/kern/subr_disk.c:1.129 Mon Sep 30 23:23:59 2019 +++ src/sys/kern/subr_disk.c Fri Mar 27 11:13:57 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_disk.c,v 1.129 2019/09/30 23:23:59 cnst Exp $ */ +/* $NetBSD: subr_disk.c,v 1.130 2020/03/27 11:13:57 mlelstv Exp $ */ /*- * Copyright (c) 1996, 1997, 1999, 2000, 2009 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.129 2019/09/30 23:23:59 cnst Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.130 2020/03/27 11:13:57 mlelstv Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -440,6 +440,10 @@ int disk_read_sectors(void (*strat)(struct buf *), const struct disklabel *lp, struct buf *bp, unsigned int sector, int count) { + + if ((lp->d_secsize / DEV_BSIZE) == 0 || lp->d_secpercyl == 0) + return EINVAL; + bp->b_blkno = btodb((off_t)sector * lp->d_secsize); bp->b_bcount = count * lp->d_secsize; bp->b_flags = (bp->b_flags & ~B_WRITE) | B_READ;