about summary refs log tree commit diff
path: root/nscd/nscd_helper.c
diff options
context:
space:
mode:
authorAndreas Jaeger <aj@suse.de>2012-05-15 20:35:53 +0200
committerAndreas Jaeger <aj@suse.de>2012-05-15 20:37:05 +0200
commit509072a0f7f8a37bedf61a78c0cdd7783368c65a (patch)
tree32ac15ad1aba98673f42bc475d053fb1b4b3b864 /nscd/nscd_helper.c
parentba75122dd93b6188d1be446df0502c4cbe5c32e6 (diff)
downloadglibc-509072a0f7f8a37bedf61a78c0cdd7783368c65a.tar.gz
glibc-509072a0f7f8a37bedf61a78c0cdd7783368c65a.tar.xz
glibc-509072a0f7f8a37bedf61a78c0cdd7783368c65a.zip
Avoid race in nscd
2012-05-15  Jeff Law  <law@redhat.com>
            Andreas Jaeger  <aj@suse.de>

        [BZ #13594]
        * nscd/nscd-client.h (__nscd_acquire_maplock): New function, split
        out from...
        * nscd/nscd_helper.c (__nscd_get_map_ref): ... here.
        * nscd/nscd-client.h: Add __nscd_acquire_maplock.
        * nscd/nscd_gethst_r.c (__nscd_get_nl_timestamp): Add locking to
        code changing __hst_map_handle.map.
Diffstat (limited to 'nscd/nscd_helper.c')
-rw-r--r--nscd/nscd_helper.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c
index 92558b6a51..96fb93db76 100644
--- a/nscd/nscd_helper.c
+++ b/nscd/nscd_helper.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2007, 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
 
@@ -419,7 +419,6 @@ __nscd_get_mapping (request_type type, const char *key,
   return result;
 }
 
-
 struct mapped_database *
 __nscd_get_map_ref (request_type type, const char *name,
 		    volatile struct locked_map_ptr *mapptr, int *gc_cyclep)
@@ -428,16 +427,8 @@ __nscd_get_map_ref (request_type type, const char *name,
   if (cur == NO_MAPPING)
     return cur;
 
-  int cnt = 0;
-  while (__builtin_expect (atomic_compare_and_exchange_val_acq (&mapptr->lock,
-								1, 0) != 0, 0))
-    {
-      // XXX Best number of rounds?
-      if (__builtin_expect (++cnt > 5, 0))
-	return NO_MAPPING;
-
-      atomic_delay ();
-    }
+  if (!__nscd_acquire_maplock (mapptr))
+    return NO_MAPPING;
 
   cur = mapptr->mapped;