summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@gmail.com>2010-12-09 12:12:58 -0500
committerAndreas Schwab <schwab@redhat.com>2010-12-13 11:41:47 +0100
commit04d5ab182b780d12092711627ceac464b711bb00 (patch)
tree4083cc0643a2bb1c75dad27446b73e03ccab4c58
parent9796df9ff2bc74bbb2bbce62628eb50265a5aa78 (diff)
downloadglibc-04d5ab182b780d12092711627ceac464b711bb00.tar.gz
glibc-04d5ab182b780d12092711627ceac464b711bb00.tar.xz
glibc-04d5ab182b780d12092711627ceac464b711bb00.zip
Fix race in qsort_r initialization.
(cherry picked from commit fb88ac72c2dcbbd979c8798e4ea497818bb3e171)
-rw-r--r--ChangeLog6
-rw-r--r--stdlib/msort.c6
2 files changed, 11 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 6a86ea7d13..ebb5342cbf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2010-12-09  Ulrich Drepper  <drepper@gmail.com>
+
+	[BZ #11655]
+	* stdlib/msort.c (qsort_r): Make sure both phys_pages and pagesize
+	are initialized.
+
 2010-12-09  Jakub Jelinek  <jakub@redhat.com>
 
 	* string/bits/string3.h (memmove, bcopy): Remove __restrict.
diff --git a/stdlib/msort.c b/stdlib/msort.c
index 35cd4d0311..fc58f0d417 100644
--- a/stdlib/msort.c
+++ b/stdlib/msort.c
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include <memcopy.h>
 #include <errno.h>
+#include <atomic.h>
 
 struct msort_param
 {
@@ -182,7 +183,7 @@ qsort_r (void *b, size_t n, size_t s, __compar_d_fn_t cmp, void *arg)
       static long int phys_pages;
       static int pagesize;
 
-      if (phys_pages == 0)
+      if (pagesize == 0)
 	{
 	  phys_pages = __sysconf (_SC_PHYS_PAGES);
 
@@ -197,6 +198,9 @@ qsort_r (void *b, size_t n, size_t s, __compar_d_fn_t cmp, void *arg)
 	     a quarter of the physical memory.  */
 	  phys_pages /= 4;
 
+	  /* Make sure phys_pages is written to memory.  */
+	  atomic_write_barrier ();
+
 	  pagesize = __sysconf (_SC_PAGESIZE);
 	}