bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-inetutils] [PATCH] Check for libidn add-on before using GNU-exclusi


From: Jaret Cantu
Subject: [bug-inetutils] [PATCH] Check for libidn add-on before using GNU-exclusive flags.
Date: Tue, 27 Oct 2015 22:42:56 -0400

The GNU-exclusive IDN flags for getaddrinfo are only usable
with glibc and when it was built with the libidn add-on. The
flags may still be defined when support does not exist, and
attempting to pass the unsupported flags into getaddrinfo
will cause it to fail.

Since there is no header which provides information about
which glibc add-ons are enabled, check for the usability of
libcidn, which is only present when the libidn add-on was
built for glibc.
---
 am/libidn.m4      | 5 +++++
 ftp/ftp.c         | 8 +++++---
 ping/libping.c    | 8 +++++---
 ping/ping6.c      | 8 +++++---
 src/tftp.c        | 8 +++++---
 src/traceroute.c  | 6 ++++--
 talk/get_addrs.c  | 4 +++-
 telnet/commands.c | 4 +++-
 8 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/am/libidn.m4 b/am/libidn.m4
index bc4c8b6..0b5acac 100644
--- a/am/libidn.m4
+++ b/am/libidn.m4
@@ -67,6 +67,11 @@ then
   fi
   CPPFLAGS=$save_CPPFLAGS
 fi
+# Check for libidn as part of the C library.
+saved_LIBS="$LIBS"
+AC_CHECK_LIB([cidn], [idna_to_ascii_lz])
+LIBS="$saved_LIBS"
+
 AC_SUBST([LIBIDN])
 AC_SUBST([INCIDN])
 ])# IU_CHECK_LIBIDN
diff --git a/ftp/ftp.c b/ftp/ftp.c
index 9813586..907686d 100644
--- a/ftp/ftp.c
+++ b/ftp/ftp.c
@@ -154,11 +154,13 @@ hookup (char *host, int port)
   hints.ai_family = usefamily;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_flags = AI_CANONNAME;
-#ifdef AI_IDN
+#ifdef HAVE_LIBCIDN
+# ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
-#endif
-#ifdef AI_CANONIDN
+# endif
+# ifdef AI_CANONIDN
   hints.ai_flags |= AI_CANONIDN;
+# endif
 #endif
 
   status = getaddrinfo (rhost, portstr, &hints, &res);
diff --git a/ping/libping.c b/ping/libping.c
index 4a9f73d..1c9f6d5 100644
--- a/ping/libping.c
+++ b/ping/libping.c
@@ -283,11 +283,13 @@ ping_set_dest (PING * ping, char *host)
   memset (&hints, 0, sizeof (hints));
   hints.ai_family = AF_INET;
   hints.ai_flags = AI_CANONNAME;
-# ifdef AI_IDN
+# ifdef HAVE_LIBCIDN
+#  ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
-# endif
-# ifdef AI_CANONIDN
+#  endif
+#  ifdef AI_CANONIDN
   hints.ai_flags |= AI_CANONIDN;
+#  endif
 # endif
 
   rc = getaddrinfo (p, NULL, &hints, &res);
diff --git a/ping/ping6.c b/ping/ping6.c
index b0e0bf1..67ba703 100644
--- a/ping/ping6.c
+++ b/ping/ping6.c
@@ -1015,11 +1015,13 @@ ping_set_dest (PING * ping, char *host)
   memset (&hints, 0, sizeof (hints));
   hints.ai_family = AF_INET6;
   hints.ai_flags = AI_CANONNAME;
-#ifdef AI_IDN
+#ifdef HAVE_LIBCIDN
+# ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
-#endif
-#ifdef AI_CANONIDN
+# endif
+# ifdef AI_CANONIDN
   hints.ai_flags |= AI_CANONIDN;
+# endif
 #endif
 
   err = getaddrinfo (rhost, NULL, &hints, &result);
diff --git a/src/tftp.c b/src/tftp.c
index d0fbd6f..7b0cf16 100644
--- a/src/tftp.c
+++ b/src/tftp.c
@@ -330,11 +330,13 @@ resolve_name (char *name)
   hints.ai_family = AF_UNSPEC;
   hints.ai_socktype = SOCK_DGRAM;
   hints.ai_flags = AI_CANONNAME;
-#ifdef AI_IDN
+#ifdef HAVE_LIBCIDN
+# ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
-#endif
-#ifdef AI_CANONIDN
+# endif
+# ifdef AI_CANONIDN
   hints.ai_flags |= AI_CANONIDN;
+# endif
 #endif
 
   err = getaddrinfo (rname, "tftp", &hints, &aiptr);
diff --git a/src/traceroute.c b/src/traceroute.c
index 785dc6f..e7b39aa 100644
--- a/src/traceroute.c
+++ b/src/traceroute.c
@@ -294,10 +294,12 @@ main (int argc, char **argv)
   memset (&hints, 0, sizeof (hints));
   hints.ai_family = AF_INET;
   hints.ai_flags = AI_CANONNAME;
-#ifdef AI_IDN
+#ifdef HAVE_LIBCIDN
+# ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
-# ifdef AI_CANONIDN
+#  ifdef AI_CANONIDN
   hints.ai_flags |= AI_CANONIDN;
+#  endif
 # endif
 #endif
 
diff --git a/talk/get_addrs.c b/talk/get_addrs.c
index 6015a50..a3186d3 100644
--- a/talk/get_addrs.c
+++ b/talk/get_addrs.c
@@ -110,8 +110,10 @@ get_addrs (char *my_machine_name, char *his_machine_name)
   /* The talk-protocol is IPv4 only!  */
   hints.ai_family = AF_INET;
   hints.ai_socktype = SOCK_DGRAM;
-# ifdef AI_IDN
+# ifdef HAVE_LIBCIDN
+#  ifdef AI_IDN
   hints.ai_flags |= AI_IDN;
+#  endif
 # endif
 
   err = getaddrinfo (lhost, NULL, &hints, &res);
diff --git a/telnet/commands.c b/telnet/commands.c
index cd0c75a..2b8e6c6 100644
--- a/telnet/commands.c
+++ b/telnet/commands.c
@@ -2619,8 +2619,10 @@ tn (int argc, char *argv[])
 
 #ifdef IPV6
   hints.ai_socktype = SOCK_STREAM;
-# ifdef AI_IDN
+# ifdef HAVE_LIBCIDN
+#  ifdef AI_IDN
   hints.ai_flags = AI_IDN;
+#  endif
 # endif
 
   err = getaddrinfo (hostp, portp, &hints, &result);
-- 
2.1.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]