INN commit: trunk (configure.ac include/clibrary.h lib/getnameinfo.c)

INN Commit rra at isc.org
Sun Dec 6 08:37:42 UTC 2020


    Date: Sunday, December 6, 2020 @ 00:37:42
  Author: iulius
Revision: 10439

Update to latest rra-c-util upstream version

Specific fixes for INN builds on Alpine and BSD:
* In the getnameinfo replacement, handle musl libc's gethostbyaddr,
which returns the string conversion of the IP address if the host
doesn't resolve.  This only affects the test suite, since musl libc
supports IPv6 and thus doesn't need this replacement.

* NetBSD prefers reallocarr to reallocarray and only prototypes the
latter if _OPENBSD_SOURCE is defined, which is not one of the macros
Autoconf defines by default.  Work around this by checking whether
reallocarray is declared, not only whether it's available, and
protyping it if it's not declared.  This uses the semi-hidden
deprecated symbol on NetBSD.

Modified:
  trunk/configure.ac
  trunk/include/clibrary.h
  trunk/lib/getnameinfo.c

--------------------+
 configure.ac       |    2 +-
 include/clibrary.h |    2 +-
 lib/getnameinfo.c  |   20 ++++++++++++++++++++
 3 files changed, 22 insertions(+), 2 deletions(-)

Modified: configure.ac
===================================================================
--- configure.ac	2020-12-06 08:35:05 UTC (rev 10438)
+++ configure.ac	2020-12-06 08:37:42 UTC (rev 10439)
@@ -487,7 +487,7 @@
               [Define if you have the <gdbm-ndbm.h> header file.])])])
 
 dnl Check for whether various symbols are declared.
-AC_CHECK_DECLS([pread, pwrite, snprintf, setproctitle, strlcat,
+AC_CHECK_DECLS([pread, pwrite, reallocarray, snprintf, setproctitle, strlcat,
                 strlcpy, vsnprintf])
 AC_CHECK_DECLS([h_errno], [], [], [#include <netdb.h>])
 AC_CHECK_DECLS([inet_aton, inet_ntoa], [], [],

Modified: include/clibrary.h
===================================================================
--- include/clibrary.h	2020-12-06 08:35:05 UTC (rev 10438)
+++ include/clibrary.h	2020-12-06 08:37:42 UTC (rev 10439)
@@ -205,7 +205,7 @@
 #if !HAVE_MKSTEMP
 extern int mkstemp(char *);
 #endif
-#if !HAVE_REALLOCARRAY
+#if !HAVE_DECL_REALLOCARRAY
 extern void *reallocarray(void *, size_t, size_t);
 #endif
 #if !HAVE_SETENV

Modified: lib/getnameinfo.c
===================================================================
--- lib/getnameinfo.c	2020-12-06 08:35:05 UTC (rev 10438)
+++ lib/getnameinfo.c	2020-12-06 08:37:42 UTC (rev 10439)
@@ -35,6 +35,7 @@
 #include "portable/socket.h"
 #include "clibrary.h"
 
+#include <ctype.h>
 #include <errno.h>
 
 /*
@@ -62,14 +63,33 @@
  * Check to see if a name is fully qualified by seeing if it contains a
  * period.  If it does, try to copy it into the provided node buffer and set
  * status accordingly, returning true.  If not, return false.
+ *
+ * musl libc returns the text form of the IP address rather than NULL when the
+ * IP address doesn't resolve.  Reject such names here so that NI_NAMEREQD is
+ * emulated correctly.
  */
 static bool
 try_name(const char *name, char *node, socklen_t nodelen, int *status)
 {
     size_t namelen;
+    const char *p;
+    bool found_nondigit = false;
 
+    /* Reject unqualified names. */
     if (strchr(name, '.') == NULL)
         return false;
+
+    /*
+     * Reject names consisting entirely of digits and period, since these are
+     * converted IP addresses rather than resolved names.
+     */
+    for (p = name; *p != '\0'; p++)
+        if (!isdigit((unsigned char) *p) && *p != '.')
+            found_nondigit = true;
+    if (!found_nondigit)
+        return false;
+
+    /* Copy the name if it's not too long and return success. */
     namelen = strlen(name);
     if (namelen + 1 > (size_t) nodelen)
         *status = EAI_OVERFLOW;



More information about the inn-committers mailing list