summaryrefslogtreecommitdiffstats
path: root/jingle
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-02 00:01:47 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-02 00:01:47 +0000
commitaa82299b37136a5de8a842d35eb893be6eb995f8 (patch)
tree9dc102beb7931c0778f413a59bb0811cf5fef43c /jingle
parent13cbec67339b2a7577f193a5c64e8a7d53ca2c9b (diff)
downloadchromium_src-aa82299b37136a5de8a842d35eb893be6eb995f8.zip
chromium_src-aa82299b37136a5de8a842d35eb893be6eb995f8.tar.gz
chromium_src-aa82299b37136a5de8a842d35eb893be6eb995f8.tar.bz2
Fixed crash involving using NetAddress::Adopt() incorrectly
Replaced use of NetAddress::Adopt() in ChromeAsyncSocket with the single-IP constructor. Clarified comment for NetAddress::Adopt(). BUG=54108 TEST=Windows sync integration tests Review URL: http://codereview.chromium.org/3353003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58273 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle')
-rw-r--r--jingle/notifier/base/chrome_async_socket.cc30
1 files changed, 13 insertions, 17 deletions
diff --git a/jingle/notifier/base/chrome_async_socket.cc b/jingle/notifier/base/chrome_async_socket.cc
index f9a852e..b3ac52a 100644
--- a/jingle/notifier/base/chrome_async_socket.cc
+++ b/jingle/notifier/base/chrome_async_socket.cc
@@ -14,10 +14,12 @@
#include <cstring>
#include <cstdlib>
+#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "net/base/address_list.h"
#include "net/base/io_buffer.h"
+#include "net/base/net_util.h"
#include "net/base/ssl_config_service.h"
#include "net/base/sys_addrinfo.h"
#include "net/socket/client_socket_factory.h"
@@ -99,26 +101,20 @@ void ChromeAsyncSocket::DoNetErrorFromStatus(int status) {
namespace {
+// Takes a 32-bit integer in host byte order and converts it to a
+// net::IPAddressNumber.
+net::IPAddressNumber Uint32ToIPAddressNumber(uint32 ip) {
+ uint32 ip_nbo = htonl(ip);
+ const unsigned char* const ip_start =
+ reinterpret_cast<const unsigned char*>(&ip_nbo);
+ return net::IPAddressNumber(ip_start, ip_start + (sizeof ip_nbo));
+}
+
net::AddressList SocketAddressToAddressList(
const talk_base::SocketAddress& address) {
DCHECK_NE(address.ip(), 0U);
- // Use malloc() as net::AddressList uses free().
- addrinfo* ai = static_cast<addrinfo*>(std::malloc(sizeof *ai));
- memset(ai, 0, sizeof *ai);
- ai->ai_family = AF_INET;
- ai->ai_socktype = SOCK_STREAM;
- ai->ai_addrlen = sizeof(sockaddr_in);
-
- sockaddr_in* addr = static_cast<sockaddr_in*>(std::malloc(sizeof *addr));
- memset(addr, 0, sizeof *addr);
- addr->sin_family = AF_INET;
- addr->sin_addr.s_addr = htonl(address.ip());
- addr->sin_port = htons(address.port());
- ai->ai_addr = reinterpret_cast<sockaddr*>(addr);
-
- net::AddressList address_list;
- address_list.Adopt(ai);
- return address_list;
+ return net::AddressList(Uint32ToIPAddressNumber(address.ip()),
+ address.port(), false);
}
} // namespace