summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpvalchev@google.com <pvalchev@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 05:12:02 +0000
committerpvalchev@google.com <pvalchev@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-31 05:12:02 +0000
commitf32c173f2633b8e5ee74715f6a7a02e286d1de29 (patch)
tree0d415f5768215d98518d8d0f84f9d11dc05ddb67
parent7a7769812fd4c6dde3242efcaab5d4276daf5b9c (diff)
downloadchromium_src-f32c173f2633b8e5ee74715f6a7a02e286d1de29.zip
chromium_src-f32c173f2633b8e5ee74715f6a7a02e286d1de29.tar.gz
chromium_src-f32c173f2633b8e5ee74715f6a7a02e286d1de29.tar.bz2
memio_SetPeerName implicitly assumes that struct sockaddr is the same as PRNetAddr, but this isn't true on *BSD
patch from sprewell@jaggeri.com Review URL: http://codereview.chromium.org/1589001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43179 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/nss_memio.c12
-rw-r--r--net/base/nss_memio.h5
-rw-r--r--net/socket/ssl_client_socket_nss.cc16
3 files changed, 19 insertions, 14 deletions
diff --git a/net/base/nss_memio.c b/net/base/nss_memio.c
index 6796882..5f7fd00 100644
--- a/net/base/nss_memio.c
+++ b/net/base/nss_memio.c
@@ -359,17 +359,11 @@ PRFileDesc *memio_CreateIOLayer(int bufsize)
return fd;
}
-void memio_SetPeerName(PRFileDesc *fd, const struct sockaddr *peername,
- size_t peername_len)
+void memio_SetPeerName(PRFileDesc *fd, const PRNetAddr *peername)
{
PRFileDesc *memiofd = PR_GetIdentitiesLayer(fd, memio_identity);
- struct PRFilePrivate *secret = memiofd->secret;
- size_t len;
-
- memset(&secret->peername, 0, sizeof(secret->peername));
- PR_ASSERT(peername_len <= sizeof(secret->peername));
- len = PR_MIN(peername_len, sizeof(secret->peername));
- memcpy(&secret->peername, peername, len);
+ struct PRFilePrivate *secret = memiofd->secret;
+ secret->peername = *peername;
}
memio_Private *memio_GetSecret(PRFileDesc *fd)
diff --git a/net/base/nss_memio.h b/net/base/nss_memio.h
index a9e6e22..a2b642a 100644
--- a/net/base/nss_memio.h
+++ b/net/base/nss_memio.h
@@ -14,8 +14,6 @@ extern "C" {
#include "prio.h"
-struct sockaddr;
-
/* Opaque structure. Really just a more typesafe alias for PRFilePrivate. */
struct memio_Private;
typedef struct memio_Private memio_Private;
@@ -42,8 +40,7 @@ typedef struct memio_Private memio_Private;
PRFileDesc *memio_CreateIOLayer(int bufsize);
/* Must call before trying to make an ssl connection */
-void memio_SetPeerName(PRFileDesc *fd, const struct sockaddr *peername,
- size_t peername_len);
+void memio_SetPeerName(PRFileDesc *fd, const PRNetAddr *peername);
/* Return a private pointer needed by the following
* four functions. (We could have passed a PRFileDesc to
diff --git a/net/socket/ssl_client_socket_nss.cc b/net/socket/ssl_client_socket_nss.cc
index a9c405d..15c11c1 100644
--- a/net/socket/ssl_client_socket_nss.cc
+++ b/net/socket/ssl_client_socket_nss.cc
@@ -319,8 +319,22 @@ int SSLClientSocketNSS::InitializeSSLOptions() {
int err = transport_->GetPeerAddress(&peer_address);
if (err != OK)
return err;
+
const struct addrinfo* ai = peer_address.head();
- memio_SetPeerName(nss_fd_, ai->ai_addr, ai->ai_addrlen);
+
+ PRNetAddr peername;
+ memset(&peername, 0, sizeof(peername));
+ DCHECK_LE(ai->ai_addrlen, sizeof(peername));
+ size_t len = std::min(static_cast<size_t>(ai->ai_addrlen), sizeof(peername));
+ memcpy(&peername, ai->ai_addr, len);
+
+ // Adjust the address family field for BSD, whose sockaddr
+ // structure has a one-byte length and one-byte address family
+ // field at the beginning. PRNetAddr has a two-byte address
+ // family field at the beginning.
+ peername.raw.family = ai->ai_addr->sa_family;
+
+ memio_SetPeerName(nss_fd_, &peername);
// Grab pointer to buffers
nss_bufs_ = memio_GetSecret(nss_fd_);