From 3f85c2e43abb3e5f88745849ea35ec0c57b53784 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 27 May 2017 20:27:33 -0400 Subject: Server: Call uv_getaddrinfo with NULL service when no port When using serverstart("ip.ad.d.r:") to listen on a random port, we need to abide by getaddrinfo()'s API and pass in a NULL service, rather than an empty string. When given an empty string, getaddrinfo() is free to search for a service by the given name (since the string isn't a number) which will fail. At least FreeBSD does perform this lookup. --- src/nvim/event/socket.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c index 82686641c0..997dd29a7f 100644 --- a/src/nvim/event/socket.c +++ b/src/nvim/event/socket.c @@ -45,6 +45,12 @@ int socket_watcher_init(Loop *loop, SocketWatcher *watcher, return UV_EINVAL; } + if (*port == NUL) { + // When no port is given, (uv_)getaddrinfo expects NULL otherwise the + // implementation may attempt to lookup the service by name (and fail) + port = NULL; + } + uv_getaddrinfo_t request; int retval = uv_getaddrinfo(&loop->uv, &request, NULL, addr, port, -- cgit