diff options
author | Andreas Jaeger <aj@suse.de> | 2012-05-15 20:35:53 +0200 |
---|---|---|
committer | Andreas Jaeger <aj@suse.de> | 2012-05-15 20:37:05 +0200 |
commit | 509072a0f7f8a37bedf61a78c0cdd7783368c65a (patch) | |
tree | 32ac15ad1aba98673f42bc475d053fb1b4b3b864 /nscd/nscd_gethst_r.c | |
parent | ba75122dd93b6188d1be446df0502c4cbe5c32e6 (diff) | |
download | glibc-509072a0f7f8a37bedf61a78c0cdd7783368c65a.zip glibc-509072a0f7f8a37bedf61a78c0cdd7783368c65a.tar.gz glibc-509072a0f7f8a37bedf61a78c0cdd7783368c65a.tar.bz2 |
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_gethst_r.c')
-rw-r--r-- | nscd/nscd_gethst_r.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/nscd/nscd_gethst_r.c b/nscd/nscd_gethst_r.c index c1661f8..d64ad2e 100644 --- a/nscd/nscd_gethst_r.c +++ b/nscd/nscd_gethst_r.c @@ -1,5 +1,4 @@ -/* Copyright (C) 1998-2005, 2006, 2007, 2008, 2009, 2011 - 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. @@ -100,9 +99,18 @@ libc_freeres_fn (hst_map_free) uint32_t __nscd_get_nl_timestamp (void) { + uint32_t retval; if (__nss_not_use_nscd_hosts != 0) return 0; + /* __nscd_get_mapping can change hst_map_handle.mapped to NO_MAPPING. + However, __nscd_get_mapping assumes the prior value was not NO_MAPPING. + Thus we have to acquire the lock to prevent this thread from changing + hst_map_handle.mapped to NO_MAPPING while another thread is inside + __nscd_get_mapping. */ + if (!__nscd_acquire_maplock (&__hst_map_handle)) + return 0; + struct mapped_database *map = __hst_map_handle.mapped; if (map == NULL @@ -112,9 +120,14 @@ __nscd_get_nl_timestamp (void) map = __nscd_get_mapping (GETFDHST, "hosts", &__hst_map_handle.mapped); if (map == NO_MAPPING) - return 0; + retval = 0; + else + retval = map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP]; + + /* Release the lock. */ + __hst_map_handle.lock = 0; - return map->head->extra_data[NSCD_HST_IDX_CONF_TIMESTAMP]; + return retval; } |