aboutsummaryrefslogtreecommitdiff
path: root/resolv/res_hconf.c
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2015-06-18 21:40:46 +0000
committerDmitry V. Levin <ldv@altlinux.org>2015-06-23 09:37:28 +0000
commitb57525f1a376149840f740a31535681c07152ba4 (patch)
treec520a3234fda67b9c99562eb1b06e090e9cc2bb5 /resolv/res_hconf.c
parent47852c972d1ad80d8b38d9e94507b27df0ede421 (diff)
downloadglibc-b57525f1a376149840f740a31535681c07152ba4.tar
glibc-b57525f1a376149840f740a31535681c07152ba4.tar.gz
glibc-b57525f1a376149840f740a31535681c07152ba4.tar.bz2
glibc-b57525f1a376149840f740a31535681c07152ba4.zip
Fix potential hanging of gethostbyaddr_r/gethostbyname_r
When "reorder" resolver option is enabled, threads of a multi-threaded process could hang in gethostbyaddr_r, gethostbyname_r, or gethostbyname2_r. Due to a trivial bug in _res_hconf_reorder_addrs, simultaneous invocations of this function in a multi-threaded process could result to _res_hconf_reorder_addrs returning without releasing the lock it holds, causing other threads to block indefinitely while waiting for the lock that is not going to be released. [BZ #17977] * resolv/res_hconf.c (_res_hconf_reorder_addrs): Fix unlocking when initializing interface list, based on the bug analysis and the patch proposed by Eric Newton. * resolv/tst-res_hconf_reorder.c: New test. * resolv/Makefile [$(have-thread-library) = yes] (tests): Add tst-res_hconf_reorder. ($(objpfx)tst-res_hconf_reorder): Depend on $(libdl) and $(shared-thread-library). (tst-res_hconf_reorder-ENV): New variable.
Diffstat (limited to 'resolv/res_hconf.c')
-rw-r--r--resolv/res_hconf.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c
index c9642ce583..0d4f3f45bc 100644
--- a/resolv/res_hconf.c
+++ b/resolv/res_hconf.c
@@ -473,10 +473,10 @@ _res_hconf_reorder_addrs (struct hostent *hp)
errno = save;
num_ifs = new_num_ifs;
-
- __libc_lock_unlock (lock);
}
+ __libc_lock_unlock (lock);
+
__close (sd);
}