Subject: another divide-by-zero in sysinst
To: None <current-users@netbsd.org>
From: Chuck Silvers <chuq@chuq.com>
List: current-users
Date: 09/18/2005 15:05:03
hi,

trying to install 3.0 or -current on this old laptop with a funky
partition table triggers a divide by zero in guess_biosgeom_from_mbr().
the problem is that xheads can be set to zero if "num" is zero,
which can be zero if both h1 and h2 are zero:

			num = (uint64_t)h1 * a2 - (quad_t)h2 * a1;

and then the line below where we compute xsectors will crash.
the simplest thing to do would be:

Index: src/distrib/utils/sysinst/mbr.c
===================================================================
RCS file: /cvsroot/src/distrib/utils/sysinst/mbr.c,v
retrieving revision 1.69
diff -u -p -r1.69 mbr.c
--- src/distrib/utils/sysinst/mbr.c	28 Aug 2005 19:57:25 -0000	1.69
+++ src/distrib/utils/sysinst/mbr.c	18 Sep 2005 22:02:39 -0000
@@ -1699,7 +1699,7 @@ guess_biosgeom_from_mbr(mbr_info_t *mbri
 			a2 -= s2;
 			num = (uint64_t)h1 * a2 - (quad_t)h2 * a1;
 			denom = (uint64_t)c2 * a1 - (quad_t)c1 * a2;
-			if (denom != 0 && num % denom == 0) {
+			if (num != 0 && denom != 0 && num % denom == 0) {
 				xheads = (int)(num / denom);
 				xsectors = a1 / (c1 * xheads + h1);
 				break;


is that ok or should we do something fancier?

-Chuck