autofs-5.1.3 - workaround getaddrinfo(3) ai_canonname bug

From: Ian Kent <raven@themaw.net>

There appears to be a bug in some versions of getaddrinfo() where the
addrinfo structure gets garbage in ai_canonname when it is not requested
by the lookup flags causing a crash or lookup fail.

Try and work around this by always requesting ai_canonname for lookups
and hope this doesn't affect the semantics of the autofs lookup usage.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG            |    1 +
 lib/parse_subs.c     |    1 +
 lib/rpc_subs.c       |    2 +-
 modules/parse_amd.c  |    2 +-
 modules/replicated.c |    4 ++--
 5 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 49798a87..35034e15 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -61,6 +61,7 @@ xx/xx/2017 autofs-5.1.4
 - fix strerror_r() parameter declaration in do program_mount().
 - fix incorrect check in validate_program_options().
 - fix log message in spawn_umount().
+- workaround getaddrinfo(3) ai_canonname bug
 
 24/05/2017 autofs-5.1.3
 =======================
diff --git a/lib/parse_subs.c b/lib/parse_subs.c
index 6bb86d3a..db784a58 100644
--- a/lib/parse_subs.c
+++ b/lib/parse_subs.c
@@ -472,6 +472,7 @@ unsigned int get_network_proximity(const char *name)
 	memset(&hints, 0, sizeof(struct addrinfo));
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_DGRAM;
+	hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_CANONNAME;
 
 	ret = getaddrinfo(name_or_num, NULL, &hints, &ni);
 	if (ret) {
diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c
index 9a267e4f..73097c9d 100644
--- a/lib/rpc_subs.c
+++ b/lib/rpc_subs.c
@@ -683,7 +683,7 @@ static int create_client(struct conn_info *info, CLIENT **client)
 	}
 
 	memset(&hints, 0, sizeof(hints));
-	hints.ai_flags = AI_ADDRCONFIG;
+	hints.ai_flags = AI_ADDRCONFIG | AI_CANONNAME;
 	hints.ai_family = AF_UNSPEC;
 	if (info->proto == IPPROTO_UDP)
 		hints.ai_socktype = SOCK_DGRAM;
diff --git a/modules/parse_amd.c b/modules/parse_amd.c
index 5d8c648a..b40c1ad1 100644
--- a/modules/parse_amd.c
+++ b/modules/parse_amd.c
@@ -264,7 +264,7 @@ static int match_my_name(unsigned int logopt, const char *name, struct substvar
 		goto out;
 	}
 
-	hints.ai_flags = 0;
+	hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_CANONNAME;
 
 	/* Resolve comparison name to its names and compare */
 	ret = getaddrinfo(name, NULL, &hints, &ni);
diff --git a/modules/replicated.c b/modules/replicated.c
index cef3bab6..3ac4c70f 100644
--- a/modules/replicated.c
+++ b/modules/replicated.c
@@ -978,7 +978,7 @@ static int add_host_addrs(struct host **list, const char *host,
 	}
 
 	memset(&hints, 0, sizeof(hints));
-	hints.ai_flags = AI_NUMERICHOST;
+	hints.ai_flags = AI_NUMERICHOST | AI_CANONNAME;
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_DGRAM;
 
@@ -998,7 +998,7 @@ static int add_host_addrs(struct host **list, const char *host,
 
 try_name:
 	memset(&hints, 0, sizeof(hints));
-	hints.ai_flags = AI_ADDRCONFIG;
+	hints.ai_flags = AI_ADDRCONFIG | AI_CANONNAME;
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_DGRAM;
 
