uv_sleep wrapper misses parentheses, causing unit test hang
Summary
uv_sleep
wrapper macro defined in lib/isc/netmgr/uv-compat.h should quote the msec
parameter with parenthesis; otherwise it could pass the wrong value to usleep
when msec
is actually a non-trivial expression.
This affects the netmgr test in connect_thread()
, specifically, on this line:
isc_test_nap(active - workers);
This would be expanded to usleep(active - worker * 1000)
, and would usually make the test hang.
As far as I can see, this is actually the only affected use case, but it could potentially affect the production code in future.
BIND version used
BIND 9.18.19 (Extended Support Version) <id:c78cd36>
running on Linux x86_64 5.10.104-linuxkit #1 SMP Thu Mar 17 17:08:06 UTC 2022
built by make with '--with-cmocka' '--disable-doh'
compiled by GCC 7.5.0
compiled with OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
linked to OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
compiled with libuv version: 1.18.0
linked to libuv version: 1.18.0
compiled with json-c version: 0.12.1
linked to json-c version: 0.12.1
compiled with zlib version: 1.2.11
linked to zlib version: 1.2.11
threads support is enabled
DNSSEC algorithms: RSASHA1 NSEC3RSASHA1 RSASHA256 RSASHA512 ECDSAP256SHA256 ECDSAP384SHA384 ED25519 ED448
DS algorithms: SHA-1 SHA-256 SHA-384
HMAC algorithms: HMAC-MD5 HMAC-SHA1 HMAC-SHA224 HMAC-SHA256 HMAC-SHA384 HMAC-SHA512
TKEY mode 2 support (Diffie-Hellman): yes
TKEY mode 3 support (GSS-API): yes
default paths:
named configuration: /usr/local/etc/named.conf
rndc configuration: /usr/local/etc/rndc.conf
DNSSEC root key: /usr/local/etc/bind.keys
nsupdate session key: /usr/local/var/run/named/session.key
named PID file: /usr/local/var/run/named/named.pid
named lock file: /usr/local/var/run/named/named.lock
Steps to reproduce
- Build BIND 9.18.19 with
----with-cmocka
and libuv older than 1.34.0 (in my case it's 1.18.0) - run
make unit
. It will hang (eventually time out) at the udp_recv_send test
What is the current bug behavior?
See the summary.
What is the expected correct behavior?
The test shouldn't time out.
Relevant configuration files
No named configuration file is needed.
Relevant logs and/or screenshots
N/A
Possible fixes
This trivial one-line patch works:
diff --git a/lib/isc/netmgr/uv-compat.h b/lib/isc/netmgr/uv-compat.h
index 3a10387..eea8744 100644
--- a/lib/isc/netmgr/uv-compat.h
+++ b/lib/isc/netmgr/uv-compat.h
@@ -72,7 +72,7 @@ uv_tcp_close_reset(uv_tcp_t *handle, uv_close_cb close_cb);
#endif
#if UV_VERSION_HEX < UV_VERSION(1, 34, 0)
-#define uv_sleep(msec) usleep(msec * 1000)
+#define uv_sleep(msec) usleep((msec) * 1000)
#endif /* UV_VERSION_HEX < UV_VERSION(1, 34, 0) */
#if UV_VERSION_HEX < UV_VERSION(1, 27, 0)