BIND 10 trac1522, updated. 8718c072463cc32d97749c2870f4f659129942ac [1522] made sockaddr_un length calculation more portable/accurate by using offsetof(struct sockaddr_un, sun_path) instead of sizeof(sun_family). the latter doesn't work for platforms that have sun_len. also use socklen_t instead of size_t mostly for being pedantic.

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Dec 22 22:55:01 UTC 2011


The branch, trac1522 has been updated
       via  8718c072463cc32d97749c2870f4f659129942ac (commit)
      from  b82303ac5c494936e9fc7dee82be764b242e48ba (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8718c072463cc32d97749c2870f4f659129942ac
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Thu Dec 22 14:53:13 2011 -0800

    [1522] made sockaddr_un length calculation more portable/accurate by using
    offsetof(struct sockaddr_un, sun_path) instead of sizeof(sun_family).
    the latter doesn't work for platforms that have sun_len.
    also use socklen_t instead of size_t mostly for being pedantic.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/server_common/socket_request.cc            |    5 +++--
 .../server_common/tests/socket_requestor_test.cc   |    5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/server_common/socket_request.cc b/src/lib/server_common/socket_request.cc
index a580b51..0c405be 100644
--- a/src/lib/server_common/socket_request.cc
+++ b/src/lib/server_common/socket_request.cc
@@ -22,6 +22,7 @@
 #include <sys/un.h>
 #include <sys/socket.h>
 #include <cerrno>
+#include <cstddef>
 
 namespace isc {
 namespace server_common {
@@ -231,8 +232,8 @@ private:
         }
 
         strcpy(sock_pass_addr.sun_path, path.c_str());
-        size_t len = strlen(sock_pass_addr.sun_path) +
-                     sizeof(sock_pass_addr.sun_family);
+        const socklen_t len = path.size() +
+            offsetof(struct sockaddr_un, sun_path);
         if (connect(sock_pass_fd,
                     (struct sockaddr *)&sock_pass_addr,
                     len) == -1) {
diff --git a/src/lib/server_common/tests/socket_requestor_test.cc b/src/lib/server_common/tests/socket_requestor_test.cc
index 47160b5..a22e1b0 100644
--- a/src/lib/server_common/tests/socket_requestor_test.cc
+++ b/src/lib/server_common/tests/socket_requestor_test.cc
@@ -23,6 +23,7 @@
 #include <server_common/tests/data_path.h>
 
 #include <cstdlib>
+#include <cstddef>
 #include <cerrno>
 #include <sys/socket.h>
 #include <sys/un.h>
@@ -321,14 +322,14 @@ private:
         }
         struct sockaddr_un socket_address;
         socket_address.sun_family = AF_UNIX;
-        int len = strlen(path_);
+        socklen_t len = strlen(path_);
         if (len > sizeof(socket_address.sun_path)) {
             isc_throw(Exception,
                       "mkstemp() created a filename too long for sun_path");
         }
         strncpy(socket_address.sun_path, path_, len);
 
-        len += sizeof(socket_address.sun_family);
+        len += offsetof(struct sockaddr_un, sun_path);
         // Remove the random file we created so we can reuse it for
         // a domain socket connection. This contains a minor race condition
         // but for the purposes of this test it should be small enough




More information about the bind10-changes mailing list