Module Name:    src
Committed By:   drochner
Date:           Thu Apr 22 14:28:48 UTC 2010

Modified Files:
        src/games/factor: factor.c

Log Message:
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)


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/games/factor/factor.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/factor/factor.c
diff -u src/games/factor/factor.c:1.19 src/games/factor/factor.c:1.20
--- src/games/factor/factor.c:1.19	Wed Aug 12 05:54:31 2009
+++ src/games/factor/factor.c	Thu Apr 22 14:28:48 2010
@@ -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) {

Reply via email to