[Gmp-commit] /var/hg/gmp: mpz_jacobi: Fix uninitialized read of low limb.

mercurial at gmplib.org mercurial at gmplib.org
Wed Dec 5 21:38:00 CET 2012


details:   /var/hg/gmp/rev/5a8d608b3d3f
changeset: 15161:5a8d608b3d3f
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Wed Dec 05 21:37:31 2012 +0100
description:
mpz_jacobi: Fix uninitialized read of low limb.

diffstat:

 ChangeLog    |   5 +++++
 mpz/jacobi.c |  10 +++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

diffs (43 lines):

diff -r 88686f17a247 -r 5a8d608b3d3f ChangeLog
--- a/ChangeLog	Wed Dec 05 19:20:37 2012 +0100
+++ b/ChangeLog	Wed Dec 05 21:37:31 2012 +0100
@@ -1,3 +1,8 @@
+2012-12-05  Niels Möller  <nisse at lysator.liu.se>
+
+	* mpz/jacobi.c (mpz_jacobi): Check for asize == 0 or bsize == 0
+	before using the low limbs.
+
 2012-12-05  Torbjorn Granlund  <tege at gmplib.org>
 
 	* mpn/generic/set_str.c (mpn_dc_set_str): Work around a valgrind issue.
diff -r 88686f17a247 -r 5a8d608b3d3f mpz/jacobi.c
--- a/mpz/jacobi.c	Wed Dec 05 19:20:37 2012 +0100
+++ b/mpz/jacobi.c	Wed Dec 05 21:37:31 2012 +0100
@@ -65,15 +65,11 @@
   bsrcp = PTR(b);
   blow = bsrcp[0];
 
-  /* The MPN jacobi functions requies positive a and b, and b odd. So
+  /* The MPN jacobi functions require positive a and b, and b odd. So
      we must to handle the cases of a or b zero, then signs, and then
      the case of even b.
   */
 
-  if ( (((alow | blow) & 1) == 0))
-    /* Common factor of 2 ==> (a/b) = 0 */
-    return 0;
-
   if (bsize == 0)
     /* (a/0) = [ a = 1 or a = -1 ] */
     return JACOBI_LS0 (alow, asize);
@@ -82,6 +78,10 @@
     /* (0/b) = [ b = 1 or b = - 1 ] */
     return JACOBI_0LS (blow, bsize);
 
+  if ( (((alow | blow) & 1) == 0))
+    /* Common factor of 2 ==> (a/b) = 0 */
+    return 0;
+
   if (bsize < 0)
     {
       /* (a/-1) = -1 if a < 0, +1 if a >= 0 */


More information about the gmp-commit mailing list