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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/socket/socket_node.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, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "nacl_io/socket/socket_node.h" 5 #include "nacl_io/socket/socket_node.h"
6 6
7 #include "nacl_io/ossocket.h" 7 #include "nacl_io/ossocket.h"
8 #ifdef PROVIDES_SOCKET_API 8 #ifdef PROVIDES_SOCKET_API
9 9
10 #include <errno.h> 10 #include <errno.h>
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 return 0; 150 return 0;
151 151
152 PP_NetAddress_IPv4 ipv4; 152 PP_NetAddress_IPv4 ipv4;
153 PP_NetAddress_IPv6 ipv6; 153 PP_NetAddress_IPv6 ipv6;
154 154
155 if (PP_TRUE == NetInterface()->DescribeAsIPv4Address(addr, &ipv4)) { 155 if (PP_TRUE == NetInterface()->DescribeAsIPv4Address(addr, &ipv4)) {
156 sockaddr_in addr4; 156 sockaddr_in addr4;
157 addr4.sin_family = AF_INET; 157 addr4.sin_family = AF_INET;
158 addr4.sin_port = ipv4.port; 158 addr4.sin_port = ipv4.port;
159 memcpy(&addr4.sin_addr, ipv4.addr, sizeof(ipv4.addr)); 159 memcpy(&addr4.sin_addr, ipv4.addr, sizeof(ipv4.addr));
160 memcpy(out_addr, &addr4, len); 160 memcpy(out_addr, &addr4,
161 std::min(len, static_cast<socklen_t>(sizeof(addr4))));
161 162
162 // Returns required size not copied size like getpeername/getsockname. 163 // Returns required size not copied size like getpeername/getsockname.
163 return sizeof(sockaddr_in); 164 return sizeof(addr4);
164 } 165 }
165 166
166 if (PP_TRUE == NetInterface()->DescribeAsIPv6Address(addr, &ipv6)) { 167 if (PP_TRUE == NetInterface()->DescribeAsIPv6Address(addr, &ipv6)) {
167 sockaddr_in6 addr6; 168 sockaddr_in6 addr6;
168 addr6.sin6_family = AF_INET6; 169 addr6.sin6_family = AF_INET6;
169 addr6.sin6_port = ipv6.port; 170 addr6.sin6_port = ipv6.port;
170 memcpy(&addr6.sin6_addr, ipv6.addr, sizeof(ipv6.addr)); 171 memcpy(&addr6.sin6_addr, ipv6.addr, sizeof(ipv6.addr));
171 memcpy(out_addr, &addr6, len); 172 memcpy(out_addr, &addr6,
173 std::min(len, static_cast<socklen_t>(sizeof(addr6))));
172 174
173 // Returns required size not copied size like getpeername/getsockname. 175 // Returns required size not copied size like getpeername/getsockname.
174 return sizeof(sockaddr_in6); 176 return sizeof(addr6);
175 } 177 }
176 178
177 return 0; 179 return 0;
178 } 180 }
179 181
180 bool SocketNode::IsEquivalentAddress(PP_Resource addr1, PP_Resource addr2) { 182 bool SocketNode::IsEquivalentAddress(PP_Resource addr1, PP_Resource addr2) {
181 if (addr1 == addr2) 183 if (addr1 == addr2)
182 return true; 184 return true;
183 185
184 char data1[sizeof(sockaddr_in6)]; 186 char data1[sizeof(sockaddr_in6)];
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 return 0; 475 return 0;
474 } 476 }
475 477
476 *len = ResourceToSockAddr(local_addr_, *len, addr); 478 *len = ResourceToSockAddr(local_addr_, *len, addr);
477 return 0; 479 return 0;
478 } 480 }
479 481
480 } // namespace nacl_io 482 } // namespace nacl_io
481 483
482 #endif // PROVIDES_SOCKET_API 484 #endif // PROVIDES_SOCKET_API
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698