Subject: Re: another divide-by-zero in sysinst
To: Chuck Silvers <chuq@chuq.com>
From: David Laight <david@l8s.co.uk>
List: current-users
Date: 09/19/2005 22:24:00
On Sun, Sep 18, 2005 at 03:05:03PM -0700, Chuck Silvers wrote:
> 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?

Should be ok, amazing how many bugs a 'simple' bit of maths has had!
Maybe it doesn't need to use uint64_t and quad_t though!

More interesting is why the sysctl() stuff failed to locate the disk.
(Or is the bios truly borked)

	David

-- 
David Laight: david@l8s.co.uk