From b666e01b9cb932de5f04fece08f21f0e5f074ebd Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Tue, 20 Jan 2015 21:07:41 +0100 Subject: [PATCH 163/506] * grub-core/loader/i386/xnu.c (guessfsb): Avoid division by 0. --- ChangeLog | 4 ++++ grub-core/loader/i386/xnu.c | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2551db..0376974 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2015-01-20 Vladimir Serbinenko + * grub-core/loader/i386/xnu.c (guessfsb): Avoid division by 0. + +2015-01-20 Vladimir Serbinenko + * grub-core/kern/i386/tsc.c (calibrate_tsc): Ensure that no division by 0 occurs. diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c index 94daa02..e0506a6 100644 --- a/grub-core/loader/i386/xnu.c +++ b/grub-core/loader/i386/xnu.c @@ -126,7 +126,7 @@ guessfsb (void) { const grub_uint64_t sane_value = 100000000; grub_uint32_t manufacturer[3], max_cpuid, capabilities, msrlow; - grub_uint32_t a, b, d; + grub_uint32_t a, b, d, divisor; if (! grub_cpu_is_cpuid_supported ()) return sane_value; @@ -166,8 +166,10 @@ guessfsb (void) r = (2000ULL << 32) - v * grub_tsc_rate; v += r / grub_tsc_rate; - return grub_divmod64 (v, ((msrlow >> 7) & 0x3e) | ((msrlow >> 14) & 1), - 0); + divisor = ((msrlow >> 7) & 0x3e) | ((msrlow >> 14) & 1); + if (divisor == 0) + return sane_value; + return grub_divmod64 (v, divisor, 0); } struct property_descriptor -- 2.4.3