Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1290)

Unified Diff: native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc

Issue 310903002: nacl_io: only copy up to the size of the sockaddr_in*, not the given len. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: stuff Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/socket/socket_node.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc
diff --git a/native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc b/native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc
index c8e45b1404bddb840341ffdf2ef956614e1e943e..850fde92bc4c1623eca20a5045da82e1fcea615d 100644
--- a/native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc
@@ -617,18 +617,42 @@ TEST_F(SocketTestTCP, Listen) {
// Pass in addrlen that is larger than our actual address to make
// sure that it is correctly set back to sizeof(sockaddr_in)
- addrlen = sizeof(addr) + 10;
- int new_socket = ki_accept(server_sock, (sockaddr*)&addr, &addrlen);
+ sockaddr_in client_addr[2];
+ sockaddr_in cmp_addr;
+ memset(&client_addr[0], 0, sizeof(client_addr[0]));
+ memset(&client_addr[1], 0xab, sizeof(client_addr[1]));
+ memset(&cmp_addr, 0xab, sizeof(cmp_addr));
+ addrlen = sizeof(client_addr[0]) + 10;
+ int new_socket = ki_accept(server_sock, (sockaddr*)&client_addr[0],
+ &addrlen);
ASSERT_GT(new_socket, -1)
<< "accept failed with " << errno << ": " << strerror(errno);
+ ASSERT_EQ(addrlen, sizeof(sockaddr_in));
+ // Check that client_addr[1] and cmp_addr are the same (not overwritten).
+ ASSERT_EQ(0, memcmp(&client_addr[1], &cmp_addr, sizeof(cmp_addr)));
+ ASSERT_EQ(0xabab, client_addr[1].sin_port);
// Verify addr and addrlen were set correctly
ASSERT_EQ(addrlen, sizeof(sockaddr_in));
- sockaddr_in client_addr;
- ASSERT_EQ(0, ki_getsockname(client_sock, (sockaddr*)&client_addr, &addrlen));
- ASSERT_EQ(client_addr.sin_family, addr.sin_family);
- ASSERT_EQ(client_addr.sin_port, addr.sin_port);
- ASSERT_EQ(client_addr.sin_addr.s_addr, addr.sin_addr.s_addr);
+ ASSERT_EQ(0, ki_getsockname(client_sock, (sockaddr*)&client_addr[1],
+ &addrlen));
+ ASSERT_EQ(client_addr[1].sin_family, client_addr[0].sin_family);
+ ASSERT_EQ(client_addr[1].sin_port, client_addr[0].sin_port);
+ ASSERT_EQ(client_addr[1].sin_addr.s_addr, client_addr[0].sin_addr.s_addr);
+
+ // Try a call where the supplied len is smaller than the expected length.
+ // The API should only write up to that amount, but should return the
+ // expected length.
+ sockaddr_in client_addr2;
+ memset(&client_addr2, 0, sizeof(client_addr2));
+ socklen_t truncated_len = sizeof(client_addr2.sin_family);
+ ASSERT_GT(sizeof(sockaddr_in), truncated_len);
+ ASSERT_EQ(0, ki_getsockname(client_sock, (sockaddr*)&client_addr2,
+ &truncated_len));
+ ASSERT_EQ(sizeof(sockaddr_in), truncated_len);
+ ASSERT_EQ(client_addr2.sin_family, client_addr[0].sin_family);
+ ASSERT_EQ(client_addr2.sin_port, 0);
+ ASSERT_EQ(client_addr2.sin_addr.s_addr, 0);
Sam Clegg 2014/06/04 00:45:28 This seems like it should be its own test really..
// Recv greeting from client and send reply
char inbuf[512];
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/socket/socket_node.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698