INN commit: trunk (3 files)

INN Commit rra at isc.org
Sun Jan 31 13:15:31 UTC 2016


    Date: Sunday, January 31, 2016 @ 05:15:30
  Author: iulius
Revision: 9984

Update to latest rra-c-util upstream version

The portable replacements for strlcat and strlcpy are no longer
maintained in rra-c-util.  These had various bugs around edge cases
and should normally be replaced with asprintf or similar functions.

Rewrite vector_join and cvector_join to use memcpy instead of strlcpy
and strlcat.

Also improve how IPv6 is handled in the network test suite.

Modified:
  trunk/lib/vector.c
  trunk/support/getrra-c-util
  trunk/tests/lib/network/server-t.c

------------------------------+
 lib/vector.c                 |   38 +++++++++++++++++++++----------
 support/getrra-c-util        |   11 +++++----
 tests/lib/network/server-t.c |   49 +++++++++++++++++++++++++++++++++++------
 3 files changed, 75 insertions(+), 23 deletions(-)

Modified: lib/vector.c
===================================================================
--- lib/vector.c	2016-01-31 13:10:58 UTC (rev 9983)
+++ lib/vector.c	2016-01-31 13:15:30 UTC (rev 9984)
@@ -464,7 +464,7 @@
 vector_join(const struct vector *vector, const char *separator)
 {
     char *string;
-    size_t i, size, seplen;
+    size_t i, length, offset, size, seplen;
 
     /* If the vector is empty, this is trivial. */
     assert(vector != NULL);
@@ -483,13 +483,20 @@
     assert(SIZE_MAX - size >= (vector->count - 1) * seplen + 1);
     size += (vector->count - 1) * seplen + 1;
 
-    /* Allocate the memory and build up the string using strlcat. */
+    /* Allocate the memory and build up the string. */
     string = xmalloc(size);
-    strlcpy(string, vector->strings[0], size);
-    for (i = 1; i < vector->count; i++) {
-        strlcat(string, separator, size);
-        strlcat(string, vector->strings[i], size);
+    offset = 0;
+    for (i = 0; i < vector->count; i++) {
+        if (i != 0) {
+            memcpy(string + offset, separator, seplen);
+            offset += seplen;
+        }
+        length = strlen(vector->strings[i]);
+        memcpy(string + offset, vector->strings[i], length);
+        offset += length;
+        assert(offset < size);
     }
+    string[offset] = '\0';
     return string;
 }
 
@@ -497,7 +504,7 @@
 cvector_join(const struct cvector *vector, const char *separator)
 {
     char *string;
-    size_t i, size, seplen;
+    size_t i, length, offset, size, seplen;
 
     /* If the vector is empty, this is trivial. */
     assert(vector != NULL);
@@ -516,13 +523,20 @@
     assert(SIZE_MAX - size >= (vector->count - 1) * seplen + 1);
     size += (vector->count - 1) * seplen + 1;
 
-    /* Allocate the memory and build up the string using strlcat. */
+    /* Allocate the memory and build up the string. */
     string = xmalloc(size);
-    strlcpy(string, vector->strings[0], size);
-    for (i = 1; i < vector->count; i++) {
-        strlcat(string, separator, size);
-        strlcat(string, vector->strings[i], size);
+    offset = 0;
+    for (i = 0; i < vector->count; i++) {
+        if (i != 0) {
+            memcpy(string + offset, separator, seplen);
+            offset += seplen;
+        }
+        length = strlen(vector->strings[i]);
+        memcpy(string + offset, vector->strings[i], length);
+        offset += length;
+        assert(offset < size);
     }
+    string[offset] = '\0';
     return string;
 }
 

Modified: support/getrra-c-util
===================================================================
--- support/getrra-c-util	2016-01-31 13:10:58 UTC (rev 9983)
+++ support/getrra-c-util	2016-01-31 13:15:30 UTC (rev 9984)
@@ -153,6 +153,13 @@
 extern int symlink(const char *, const char *);\\
 #endif\\
 " \
+               -e "154 i \\
+#if !HAVE_DECL_STRLCAT\\
+extern size_t strlcat(char *, const char *, size_t);\\
+#endif\\
+#if !HAVE_DECL_STRLCPY\\
+extern size_t strlcpy(char *, const char *, size_t);\\
+#endif" \
                -e '/#if !HAVE_DAEMON/,+2d' \
                -e '/#if !HAVE_ISSETUGID/,+2d' \
                -e '/#if !HAVE_STRNDUP/,+2d' \
@@ -238,8 +245,6 @@
 download portable/socket.h include/portable socket.h
 download portable/socket-unix.h include/portable socket-unix.h
 download portable/stdbool.h include/portable stdbool.h
-download portable/strlcat.c lib strlcat.c
-download portable/strlcpy.c lib strlcpy.c
 download portable/system.h include clibrary.h
 download portable/uio.h include/portable uio.h
 
@@ -271,8 +276,6 @@
 download tests/portable/reallocarray-t.c tests/lib reallocarray-t.c
 download tests/portable/setenv-t.c tests/lib setenv-t.c
 download tests/portable/snprintf-t.c tests/lib snprintf-t.c
-download tests/portable/strlcat-t.c tests/lib strlcat-t.c
-download tests/portable/strlcpy-t.c tests/lib strlcpy-t.c
 
 ##  Synchronize test suite files for utility functions from upstream.
 download tests/util/buffer-t.c tests/lib buffer-t.c

Modified: tests/lib/network/server-t.c
===================================================================
--- tests/lib/network/server-t.c	2016-01-31 13:10:58 UTC (rev 9983)
+++ tests/lib/network/server-t.c	2016-01-31 13:15:30 UTC (rev 9984)
@@ -6,7 +6,7 @@
  * which can be found at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2005, 2013 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2005, 2013, 2016 Russ Allbery <eagle at eyrie.org>
  * Copyright 2009, 2010, 2011, 2012, 2013
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -40,6 +40,7 @@
 #include <signal.h>
 
 #include "tap/basic.h"
+#include "inn/fdflag.h"
 #include "inn/macros.h"
 #include "inn/messages.h"
 #include "inn/network.h"
@@ -57,21 +58,41 @@
 static bool
 ipv6_works(void)
 {
-    socket_type fd;
+    socket_type fd, client, server;
 
-    /* Create the socket.  If this works, ipv6 is supported. */
+    /*
+     * Create the socket and then try to connect to it with a short timeout
+     * and accept it on the server side.  If this works, IPv6 is supported.
+     */
     fd = network_bind_ipv6(SOCK_STREAM, "::1", 11119);
     if (fd != INVALID_SOCKET) {
-        close(fd);
-        return true;
+        fdflag_nonblocking(fd, true);
+        client = network_connect_host("::1", 11119, NULL, 1);
+        if (client == INVALID_SOCKET) {
+            close(fd);
+            if (socket_errno == ETIMEDOUT || socket_errno == ENETUNREACH)
+                return false;
+        } else {
+            server = accept(fd, NULL, NULL);
+            close(fd);
+            if (server == INVALID_SOCKET) {
+                close(client);
+                if (socket_errno == EAGAIN || socket_errno == EWOULDBLOCK)
+                    return false;
+            } else {
+                close(server);
+                close(client);
+                return true;
+            }
+        }
     }
 
     /* IPv6 not recognized, indicating no support. */
-    if (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT)
+    if (socket_errno == EAFNOSUPPORT || socket_errno == EPROTONOSUPPORT)
         return false;
 
     /* IPv6 is recognized but we can't actually use it. */
-    if (errno == EADDRNOTAVAIL)
+    if (socket_errno == EADDRNOTAVAIL)
         return false;
 
     /*
@@ -190,9 +211,16 @@
 {
     socket_type client;
 
+    /* If there are firewalls that block connections, we could hang here. */
+    alarm(5);
+
+    /* Accept the connection and writes from the client. */
     client = accept(fd, NULL, NULL);
     test_server_connection(client);
     socket_close(fd);
+
+    /* Cancel the alarm. */
+    alarm(0);
 }
 
 
@@ -215,6 +243,10 @@
     struct sockaddr *saddr;
     socklen_t slen;
 
+    /* If there are firewalls that block connections, we could hang here. */
+    alarm(5);
+
+    /* Accept the connection and writes from the client. */
     slen = sizeof(struct sockaddr_storage);
     saddr = bcalloc(1, slen);
     client = network_accept_any(fds, count, saddr, &slen);
@@ -226,6 +258,9 @@
     free(saddr);
     for (i = 0; i < count; i++)
         socket_close(fds[i]);
+
+    /* Cancel the alarm. */
+    alarm(0);
 }
 
 



More information about the inn-committers mailing list