Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/factor fix an obvious flaw in bounds check: the array ...



details:   https://anonhg.NetBSD.org/src/rev/a02c82f86652
branches:  trunk
changeset: 754163:a02c82f86652
user:      drochner <drochner%NetBSD.org@localhost>
date:      Thu Apr 22 14:28:48 2010 +0000

description:
fix an obvious flaw in bounds check: the array of precomputed primes
could be overrun if its last entry (65537) was a factor of the input
(this does not affect PR misc/43192 -- the factors are much larger
here: 7742394596501*159455563099482401)

diffstat:

 games/factor/factor.c |  9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diffs (32 lines):

diff -r 9ba10a4fe44f -r a02c82f86652 games/factor/factor.c
--- a/games/factor/factor.c     Thu Apr 22 13:41:40 2010 +0000
+++ b/games/factor/factor.c     Thu Apr 22 14:28:48 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: factor.c,v 1.19 2009/08/12 05:54:31 dholland Exp $     */
+/*     $NetBSD: factor.c,v 1.20 2010/04/22 14:28:48 drochner Exp $     */
 
 /*
  * Copyright (c) 1989, 1993
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)factor.c   8.4 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: factor.c,v 1.19 2009/08/12 05:54:31 dholland Exp $");
+__RCSID("$NetBSD: factor.c,v 1.20 2010/04/22 14:28:48 drochner Exp $");
 #endif
 #endif /* not lint */
 
@@ -214,10 +214,11 @@
        putchar(':');
        for (fact = &prime[0]; !BN_is_one(val); ++fact) {
                /* Look for the smallest factor. */
-               do {
+               while (fact <= pr_limit) {
                        if (BN_mod_word(val, (BN_ULONG)*fact) == 0)
                                break;
-               } while (++fact <= pr_limit);
+                       fact++;
+               }
 
                /* Watch for primes larger than the table. */
                if (fact > pr_limit) {



Home | Main Index | Thread Index | Old Index