Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Sep 2009 12:55:09 +0000 (UTC)
From:      Attilio Rao <attilio@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-6@freebsd.org
Subject:   svn commit: r197061 - stable/6/contrib/gdtoa
Message-ID:  <200909101255.n8ACt9EO020011@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: attilio
Date: Thu Sep 10 12:55:09 2009
New Revision: 197061
URL: http://svn.freebsd.org/changeset/base/197061

Log:
  MFC r196916:
  Fix a list overrun.
  
  Sponsored by: Sandvine Incorporated

Modified:
  stable/6/contrib/gdtoa/gdtoaimp.h
  stable/6/contrib/gdtoa/misc.c

Modified: stable/6/contrib/gdtoa/gdtoaimp.h
==============================================================================
--- stable/6/contrib/gdtoa/gdtoaimp.h	Thu Sep 10 12:42:36 2009	(r197060)
+++ stable/6/contrib/gdtoa/gdtoaimp.h	Thu Sep 10 12:55:09 2009	(r197061)
@@ -479,7 +479,7 @@ extern pthread_mutex_t __gdtoa_locks[2];
 		_pthread_mutex_unlock(&__gdtoa_locks[n]);	\
 } while(0)
 
-#define Kmax 15
+#define Kmax 9
 
  struct
 Bigint {

Modified: stable/6/contrib/gdtoa/misc.c
==============================================================================
--- stable/6/contrib/gdtoa/misc.c	Thu Sep 10 12:42:36 2009	(r197060)
+++ stable/6/contrib/gdtoa/misc.c	Thu Sep 10 12:55:09 2009	(r197061)
@@ -61,7 +61,9 @@ Balloc
 #endif
 
 	ACQUIRE_DTOA_LOCK(0);
-	if ( (rv = freelist[k]) !=0) {
+	/* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */
+	/* but this case seems very unlikely. */
+	if (k <= Kmax && (rv = freelist[k]) !=0) {
 		freelist[k] = rv->next;
 		}
 	else {
@@ -71,7 +73,7 @@ Balloc
 #else
 		len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
 			/sizeof(double);
-		if (pmem_next - private_mem + len <= PRIVATE_mem) {
+		if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {
 			rv = (Bigint*)pmem_next;
 			pmem_next += len;
 			}
@@ -95,10 +97,14 @@ Bfree
 #endif
 {
 	if (v) {
-		ACQUIRE_DTOA_LOCK(0);
-		v->next = freelist[v->k];
-		freelist[v->k] = v;
-		FREE_DTOA_LOCK(0);
+		if (v->k > Kmax)
+			free((void*)v);
+		else {
+			ACQUIRE_DTOA_LOCK(0);
+			v->next = freelist[v->k];
+			freelist[v->k] = v;
+			FREE_DTOA_LOCK(0);
+			}
 		}
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200909101255.n8ACt9EO020011>