diff options
author | Josh Gao <jmgao@google.com> | 2016-08-23 15:28:43 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2016-08-24 13:06:06 -0700 |
commit | 5990191c4e4802567881db2f19db4adbddc64e1e (patch) | |
tree | ad4ddc3d892fe428e68d04efa01c7a5696f61999 /adb/sysdeps_win32.cpp | |
parent | 704d818ec1eed59b0f6fb3f2463f630121139df2 (diff) | |
download | system_core-5990191c4e4802567881db2f19db4adbddc64e1e.tar.gz system_core-5990191c4e4802567881db2f19db4adbddc64e1e.tar.bz2 system_core-5990191c4e4802567881db2f19db4adbddc64e1e.zip |
adb: check our socketpair ends in our win32 emulation.
In our Win32 socketpair emulation, check that the ends are properly
connected before returning.
Change-Id: I33d356fd9ebcac89fc6a89a5200e926032220383
Test: no additional failing tests in adb_test.exe
Diffstat (limited to 'adb/sysdeps_win32.cpp')
-rw-r--r-- | adb/sysdeps_win32.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/adb/sysdeps_win32.cpp b/adb/sysdeps_win32.cpp index 109a5486c..5fda27b8a 100644 --- a/adb/sysdeps_win32.cpp +++ b/adb/sysdeps_win32.cpp @@ -1061,7 +1061,7 @@ int adb_getsockname(int fd, struct sockaddr* sockaddr, socklen_t* optlen) { return -1; } - int result = getsockname(fh->fh_socket, sockaddr, optlen); + int result = (getsockname)(fh->fh_socket, sockaddr, optlen); if (result == SOCKET_ERROR) { const DWORD err = WSAGetLastError(); D("adb_getsockname: setsockopt on fd %d failed: %s\n", fd, @@ -1119,6 +1119,11 @@ int adb_socketpair(int sv[2]) { int local_port = -1; std::string error; + struct sockaddr_storage peer_addr = {}; + struct sockaddr_storage client_addr = {}; + socklen_t peer_socklen = sizeof(peer_addr); + socklen_t client_socklen = sizeof(client_addr); + server = network_loopback_server(0, SOCK_STREAM, &error); if (server < 0) { D("adb_socketpair: failed to create server: %s", error.c_str()); @@ -1138,12 +1143,32 @@ int adb_socketpair(int sv[2]) { goto fail; } - accepted = adb_socket_accept(server, nullptr, nullptr); + // Make sure that the peer that connected to us and the client are the same. + accepted = adb_socket_accept(server, reinterpret_cast<sockaddr*>(&peer_addr), &peer_socklen); if (accepted < 0) { D("adb_socketpair: failed to accept: %s", strerror(errno)); goto fail; } + + if (adb_getsockname(client, reinterpret_cast<sockaddr*>(&client_addr), &client_socklen) != 0) { + D("adb_socketpair: failed to getpeername: %s", strerror(errno)); + goto fail; + } + + if (peer_socklen != client_socklen) { + D("adb_socketpair: client and peer sockaddrs have different lengths"); + errno = EIO; + goto fail; + } + + if (memcmp(&peer_addr, &client_addr, peer_socklen) != 0) { + D("adb_socketpair: client and peer sockaddrs don't match"); + errno = EIO; + goto fail; + } + adb_close(server); + sv[0] = client; sv[1] = accepted; return 0; |