All of lore.kernel.org
 help / color / mirror / Atom feed
* A divide by zero bug in lib/math/rational.c (with triggering input)
@ 2021-05-21  5:09 Yiyuan guo
       [not found] ` <CAHp75Vf8kQ73w0R9ieDNjDVkxM-V83QRN9mc6BjRZA8xHpPNAA@mail.gmail.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Yiyuan guo @ 2021-05-21  5:09 UTC (permalink / raw)
  To: linux-kernel; +Cc: andy, tpiepho, akpm, oskar, Yiyuan guo

In the file lib/math/rational.c, the function
rational_best_approximation has the following
code:

void rational_best_approximation(
    unsigned long given_numerator, unsigned long given_denominator,
    unsigned long max_numerator, unsigned long max_denominator,
    unsigned long *best_numerator, unsigned long *best_denominator) {
   ...
   if ((n2 > max_numerator) || (d2 > max_denominator)) {
            unsigned long t = min((max_numerator - n0) / n1,
                          (max_denominator - d0) / d1);
   ...
}

d1 may be equal to zero when performing the division, leading to a
divide by zero problem.

One input  to trigger the divide by zero bug is:
rational_best_approximation(31415, 100, (1 << 8) - 1, (1 << 5) - 1, &n, &d)

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-24  3:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21  5:09 A divide by zero bug in lib/math/rational.c (with triggering input) Yiyuan guo
     [not found] ` <CAHp75Vf8kQ73w0R9ieDNjDVkxM-V83QRN9mc6BjRZA8xHpPNAA@mail.gmail.com>
     [not found]   ` <CAHp75Vft8pnA+m0C=Ok7nRyjERAd2uJJ4q6HcN460j0Hir6Kaw@mail.gmail.com>
2021-05-21  7:55     ` Yiyuan guo
2021-05-21  9:20       ` Trent Piepho
2021-05-21  9:53         ` Andy Shevchenko
2021-05-22 19:07           ` Oskar Schirmer
2021-05-24  3:20             ` Trent Piepho
2021-05-23  0:05           ` Trent Piepho

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.