From b57525f1a376149840f740a31535681c07152ba4 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Thu, 18 Jun 2015 21:40:46 +0000 Subject: 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. --- resolv/res_hconf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'resolv/res_hconf.c') 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); } -- cgit 1.4.1