INN commit: branches/2.6 (13 files)

INN Commit rra at isc.org
Fri Nov 4 22:42:26 UTC 2016


    Date: Friday, November 4, 2016 @ 15:42:26
  Author: iulius
Revision: 10105

Update to latest rra-c-util version

Notably:

Correct the return-value checks for snprintf to avoid an off-by-one
error when verifying the output was not truncated. (All locations
should have been safe anyway for other reasons, but be certain.)
Based on a patch by Yuriy M. Kaminskiy.

Add more debugging information to network/server test.

Fix incorrect use of IPv6 protocol in IPv4 test.

When testing network_set_reuseaddr and related functions, don't
require that the option be set to 1 explicitly, just that it has
a true value. Debian/kFreeBSD returns the numeric value of the
socket option in some cases when the socket option is set rather
than returning 1, and POSIX just documents that this is a boolean
flag (so only the truthfulness of the value matters).

Increase the buffer size of the network write timeout test:
the default Debian cloud images use a 12MB TCP sending buffer,
which meant that the timeout test never triggered because the
entire write of 8MB was absorbed by the buffer. Bump the buffer
size to 15MB and add a comment explaining why that number was
chosen, with a reference to the Debian bug where the Ruby
maintainers sorted this out.
Many thanks to Lucas Nussbaum for investigating this and to
Eric Wong for sorting out why this buffer was causing tests to
fail.

Modified:
  branches/2.6/include/inn/buffer.h
  branches/2.6/include/inn/messages.h
  branches/2.6/lib/buffer.c
  branches/2.6/lib/getnameinfo.c
  branches/2.6/lib/inet_ntop.c
  branches/2.6/lib/messages.c
  branches/2.6/lib/network-innbind.c
  branches/2.6/lib/network.c
  branches/2.6/lib/snprintf.c
  branches/2.6/tests/lib/network/addr-ipv4-t.c
  branches/2.6/tests/lib/network/addr-ipv6-t.c
  branches/2.6/tests/lib/network/client-t.c
  branches/2.6/tests/lib/network/server-t.c

---------------------------------+
 include/inn/buffer.h            |    2 +-
 include/inn/messages.h          |    2 ++
 lib/buffer.c                    |    5 +++--
 lib/getnameinfo.c               |    2 +-
 lib/inet_ntop.c                 |    2 +-
 lib/messages.c                  |    5 +++--
 lib/network-innbind.c           |    2 +-
 lib/network.c                   |    4 ++--
 lib/snprintf.c                  |    9 +++++----
 tests/lib/network/addr-ipv4-t.c |    4 ++--
 tests/lib/network/addr-ipv6-t.c |    6 +++---
 tests/lib/network/client-t.c    |   19 ++++++++++++++-----
 tests/lib/network/server-t.c    |    5 +++--
 13 files changed, 41 insertions(+), 26 deletions(-)

Modified: include/inn/buffer.h
===================================================================
--- include/inn/buffer.h	2016-11-04 22:41:36 UTC (rev 10104)
+++ include/inn/buffer.h	2016-11-04 22:42:26 UTC (rev 10105)
@@ -17,7 +17,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2014 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2014, 2015 Russ Allbery <eagle at eyrie.org>
  * Copyright 2011, 2012
  *     The Board of Trustees of the Leland Stanford Junior University
  * Copyright (c) 2004, 2005, 2006

Modified: include/inn/messages.h
===================================================================
--- include/inn/messages.h	2016-11-04 22:41:36 UTC (rev 10104)
+++ include/inn/messages.h	2016-11-04 22:42:26 UTC (rev 10105)
@@ -5,6 +5,8 @@
  * The canonical version of this file is maintained in the rra-c-util package,
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
+ * Written by Russ Allbery <eagle at eyrie.org>
+ * Copyright 2015 Russ Allbery <eagle at eyrie.org>
  * Copyright 2008, 2010, 2013, 2014
  *     The Board of Trustees of the Leland Stanford Junior University
  * Copyright (c) 2004, 2005, 2006

Modified: lib/buffer.c
===================================================================
--- lib/buffer.c	2016-11-04 22:41:36 UTC (rev 10104)
+++ lib/buffer.c	2016-11-04 22:42:26 UTC (rev 10105)
@@ -17,6 +17,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
+ * Copyright 2015, 2016 Russ Allbery <eagle at eyrie.org>
  * Copyright 2011, 2012, 2014
  *     The Board of Trustees of the Leland Stanford Junior University
  * Copyright (c) 2004, 2005, 2006
@@ -156,13 +157,13 @@
     va_end(args_copy);
     if (status < 0)
         return;
-    if ((size_t) status + 1 <= avail) {
+    if ((size_t) status < avail) {
         buffer->left += status;
     } else {
         buffer_resize(buffer, total + status + 1);
         avail = buffer->size - total;
         status = vsnprintf(buffer->data + total, avail, format, args);
-        if (status < 0 || (size_t) status + 1 > avail)
+        if (status < 0 || (size_t) status >= avail)
             return;
         buffer->left += status;
     }

Modified: lib/getnameinfo.c
===================================================================
--- lib/getnameinfo.c	2016-11-04 22:41:36 UTC (rev 10104)
+++ lib/getnameinfo.c	2016-11-04 22:42:26 UTC (rev 10105)
@@ -154,7 +154,7 @@
 
     /* Just convert the port number to ASCII. */
     status = snprintf(service, servicelen, "%hu", port);
-    if (status < 0 || (socklen_t) status > servicelen)
+    if (status < 0 || (socklen_t) status >= servicelen)
         return EAI_OVERFLOW;
     return 0;
 }

Modified: lib/inet_ntop.c
===================================================================
--- lib/inet_ntop.c	2016-11-04 22:41:36 UTC (rev 10104)
+++ lib/inet_ntop.c	2016-11-04 22:42:26 UTC (rev 10105)
@@ -68,7 +68,7 @@
                       (unsigned int) (p[1] & 0xff),
                       (unsigned int) (p[2] & 0xff),
                       (unsigned int) (p[3] & 0xff));
-    if (status < 0)
+    if (status < 0 || (size_t) status >= (size_t) size)
         return NULL;
     return dst;
 }

Modified: lib/messages.c
===================================================================
--- lib/messages.c	2016-11-04 22:41:36 UTC (rev 10104)
+++ lib/messages.c	2016-11-04 22:42:26 UTC (rev 10105)
@@ -55,7 +55,8 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2008, 2009, 2010, 2013
+ * Copyright 2015, 2016 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2008, 2009, 2010, 2013, 2014
  *     The Board of Trustees of the Leland Stanford Junior University
  * Copyright (c) 2004, 2005, 2006
  *     by Internet Systems Consortium, Inc. ("ISC")
@@ -239,7 +240,7 @@
         exit(message_fatal_cleanup ? (*message_fatal_cleanup)() : 1);
     }
     status = vsnprintf(buffer, len + 1, fmt, args);
-    if (status < 0) {
+    if (status < 0 || (size_t) status >= len + 1) {
         warn("failed to format output with vsnprintf in syslog handler");
         free(buffer);
         return;

Modified: lib/network-innbind.c
===================================================================
--- lib/network-innbind.c	2016-11-04 22:41:36 UTC (rev 10104)
+++ lib/network-innbind.c	2016-11-04 22:42:26 UTC (rev 10105)
@@ -297,7 +297,7 @@
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = type;
     status = snprintf(service, sizeof(service), "%hu", port);
-    if (status < 0 || (size_t) status > sizeof(service)) {
+    if (status < 0 || (size_t) status >= sizeof(service)) {
         warn("cannot convert port %hu to string", port);
         socket_set_errno_einval();
         return false;

Modified: lib/network.c
===================================================================
--- lib/network.c	2016-11-04 22:41:36 UTC (rev 10104)
+++ lib/network.c	2016-11-04 22:42:26 UTC (rev 10105)
@@ -294,7 +294,7 @@
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = type;
     status = snprintf(service, sizeof(service), "%hu", port);
-    if (status < 0 || (size_t) status > sizeof(service)) {
+    if (status < 0 || (size_t) status >= sizeof(service)) {
         warn("cannot convert port %hu to string", port);
         socket_set_errno_einval();
         return false;
@@ -612,7 +612,7 @@
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
     status = snprintf(portbuf, sizeof(portbuf), "%hu", port);
-    if (status > 0 && (size_t) status > sizeof(portbuf)) {
+    if (status > 0 && (size_t) status >= sizeof(portbuf)) {
         status = -1;
         socket_set_errno_einval();
     }

Modified: lib/snprintf.c
===================================================================
--- lib/snprintf.c	2016-11-04 22:41:36 UTC (rev 10104)
+++ lib/snprintf.c	2016-11-04 22:42:26 UTC (rev 10105)
@@ -80,6 +80,7 @@
  *  Russ Allbery <eagle at eyrie.org> 2000-08-26
  *    fixed return value to comply with C99
  *    fixed handling of snprintf(NULL, ...)
+ *    added explicit casts for double to long long int conversion
  *
  *  Hrvoje Niksic <hniksic at arsdigita.com> 2000-11-04
  *    include <stdio.h> for NULL.
@@ -613,7 +614,7 @@
   return result;
 }
 
-static LDOUBLE pow10_int (int exp)
+static LLONG pow10_int (int exp)
 {
   LDOUBLE result = 1;
 
@@ -623,7 +624,7 @@
     exp--;
   }
   
-  return result;
+  return (LLONG) result;
 }
 
 static LLONG round_int (LDOUBLE value)
@@ -630,7 +631,7 @@
 {
   LLONG intpart;
 
-  intpart = value;
+  intpart = (LLONG) value;
   value = value - intpart;
   if (value >= 0.5)
     intpart++;
@@ -679,7 +680,7 @@
   if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
 #endif
 
-  intpart = ufvalue;
+  intpart = (LLONG) ufvalue;
 
   /* With %g precision is the number of significant digits, which
      includes the digits in intpart. */

Modified: tests/lib/network/addr-ipv4-t.c
===================================================================
--- tests/lib/network/addr-ipv4-t.c	2016-11-04 22:41:36 UTC (rev 10104)
+++ tests/lib/network/addr-ipv4-t.c	2016-11-04 22:42:26 UTC (rev 10105)
@@ -130,7 +130,7 @@
     is_addr_compare(0, "127.0.0.1", "127.0.0.1",   "33");
 
     /* Test setting various socket options. */
-    fd = socket(PF_INET6, SOCK_STREAM, IPPROTO_IP);
+    fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
     if (fd == INVALID_SOCKET)
         sysbail("cannot create socket");
     network_set_reuseaddr(fd);
@@ -139,7 +139,7 @@
     flaglen = sizeof(flag);
     is_int(0, getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &flag, &flaglen),
            "Getting SO_REUSEADDR works");
-    is_int(1, flag, "...and it is set");
+    ok(flag, "...and it is set");
 #else
     skip_block(2, "SO_REUSEADDR not supported");
 #endif

Modified: tests/lib/network/addr-ipv6-t.c
===================================================================
--- tests/lib/network/addr-ipv6-t.c	2016-11-04 22:41:36 UTC (rev 10104)
+++ tests/lib/network/addr-ipv6-t.c	2016-11-04 22:42:26 UTC (rev 10105)
@@ -158,7 +158,7 @@
     flaglen = sizeof(flag);
     is_int(0, getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &flag, &flaglen),
            "Getting SO_REUSEADDR works");
-    is_int(1, flag, "...and it is set");
+    ok(flag, "...and it is set");
 #else
     skip_block(2, "SO_REUSEADDR not supported");
 #endif
@@ -168,7 +168,7 @@
     flaglen = sizeof(flag);
     is_int(0, getsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &flag, &flaglen),
            "Getting IPV6_V6ONLY works");
-    is_int(1, flag, "...and it is set");
+    ok(flag, "...and it is set");
 #else
     skip_block(2, "IPV6_V6ONLY not supported");
 #endif
@@ -178,7 +178,7 @@
     flaglen = sizeof(flag);
     is_int(0, getsockopt(fd, IPPROTO_IP, IP_FREEBIND, &flag, &flaglen),
            "Getting IP_FREEBIND works");
-    is_int(1, flag, "...and it is set");
+    ok(flag, "...and it is set");
 #else
     skip_block(2, "IP_FREEBIND not supported");
 #endif

Modified: tests/lib/network/client-t.c
===================================================================
--- tests/lib/network/client-t.c	2016-11-04 22:41:36 UTC (rev 10104)
+++ tests/lib/network/client-t.c	2016-11-04 22:42:26 UTC (rev 10105)
@@ -6,7 +6,7 @@
  * which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
  *
  * Written by Russ Allbery <eagle at eyrie.org>
- * Copyright 2005, 2013, 2014 Russ Allbery <eagle at eyrie.org>
+ * Copyright 2005, 2013, 2014, 2016 Russ Allbery <eagle at eyrie.org>
  * Copyright 2009, 2010, 2011, 2012, 2013
  *     The Board of Trustees of the Leland Stanford Junior University
  *
@@ -373,9 +373,15 @@
     pid_t child;
     char *buffer;
 
+    /*
+     * 15MB chosen because it's larger than the default TCP buffer size of
+     * 12MB used by Debian cloud images (see https://bugs.debian.org/830353).
+     */
+    const size_t bufsize = 15 * 1024 * 1024;
+
     /* Create the data that we're going to send. */
-    buffer = bmalloc(8192 * 1024);
-    memset(buffer, 'a', 8192 * 1024);
+    buffer = bmalloc(bufsize);
+    memset(buffer, 'a', bufsize);
 
     /* Create the listening socket. */
     fd = network_bind_ipv4(SOCK_STREAM, "127.0.0.1", 11119);
@@ -401,7 +407,10 @@
     if (c == INVALID_SOCKET)
         sysbail("cannot accept on socket");
 
-    /* Test some successful writes with and without a timeout. */
+    /*
+     * Test some successful writes with and without a timeout.  Don't send
+     * the whole giant buffer here to make the test run a bit faster.
+     */
     socket_set_errno(0);
     ok(network_write(c, buffer, 32 * 1024, 0), "network_write");
     ok(network_write(c, buffer, 32 * 1024, 1),
@@ -411,7 +420,7 @@
      * A longer write cannot be completely absorbed before the client sleep,
      * so should fail with a timeout.
      */
-    ok(!network_write(c, buffer, 8192 * 1024, 1),
+    ok(!network_write(c, buffer, bufsize, 1),
        "network_write aborted with timeout");
     is_int(ETIMEDOUT, socket_errno, "...with correct error");
     alarm(0);

Modified: tests/lib/network/server-t.c
===================================================================
--- tests/lib/network/server-t.c	2016-11-04 22:41:36 UTC (rev 10104)
+++ tests/lib/network/server-t.c	2016-11-04 22:42:26 UTC (rev 10105)
@@ -407,7 +407,7 @@
         fd = fds[i];
         if (listen(fd, 1) < 0)
             sysbail("cannot listen to socket %d", fd);
-        ok(fd != INVALID_SOCKET, "all address server test (part %d)", i + 1);
+        ok(fd != INVALID_SOCKET, "all address server test (part %u)", i + 1);
 
         /* Get the socket type to determine what type of client to run. */
         saddr = get_sockaddr(fd);
@@ -462,6 +462,7 @@
 
     if (!network_bind_all(SOCK_STREAM, 11119, &fds, &count))
         sysbail("cannot create or bind socket");
+    ok(1, "network_accept_any test");
     for (i = 0; i < count; i++)
         if (listen(fds[i], 1) < 0)
             sysbail("cannot listen to socket %d", fds[i]);
@@ -547,7 +548,7 @@
 main(void)
 {
     /* Set up the plan. */
-    plan(42);
+    plan(43);
 
     /* Test network_bind functions. */
     test_ipv4(NULL);



More information about the inn-committers mailing list