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

Side by Side Diff: net/socket/ssl_client_socket.cc

Issue 798603002: Remove memcpy from SSLClientSocket::SerializeNextProtos. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/socket/ssl_client_socket.h" 5 #include "net/socket/ssl_client_socket.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/metrics/sparse_histogram.h" 8 #include "base/metrics/sparse_histogram.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "crypto/ec_private_key.h" 10 #include "crypto/ec_private_key.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 DVLOG(1) << "System time is not within the supported range for certificate " 229 DVLOG(1) << "System time is not within the supported range for certificate "
230 "generation, not enabling channel ID."; 230 "generation, not enabling channel ID.";
231 return false; 231 return false;
232 } 232 }
233 return true; 233 return true;
234 } 234 }
235 235
236 // static 236 // static
237 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos( 237 std::vector<uint8_t> SSLClientSocket::SerializeNextProtos(
238 const NextProtoVector& next_protos) { 238 const NextProtoVector& next_protos) {
239 // Do a first pass to determine the total length. 239 std::vector<uint8_t> wire_protos;
240 size_t wire_length = 0;
241 std::vector<std::string> next_proto_strings;
242 for (const NextProto next_proto : next_protos) { 240 for (const NextProto next_proto : next_protos) {
243 const std::string proto = NextProtoToString(next_proto); 241 const std::string proto = NextProtoToString(next_proto);
244 if (proto.size() > 255) { 242 if (proto.size() > 255) {
245 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << proto; 243 LOG(WARNING) << "Ignoring overlong NPN/ALPN protocol: " << proto;
246 continue; 244 continue;
247 } 245 }
248 if (proto.size() == 0) { 246 if (proto.size() == 0) {
249 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol"; 247 LOG(WARNING) << "Ignoring empty NPN/ALPN protocol";
250 continue; 248 continue;
251 } 249 }
252 next_proto_strings.push_back(proto); 250 wire_protos.push_back(proto.size());
253 wire_length += proto.size(); 251 for (const auto ch : proto) {
Ryan Hamilton 2014/12/11 19:58:41 s/auto/char/ (I assume it's a char?)
Bence 2014/12/12 13:22:25 You are right, the standard requires it in Section
254 wire_length++; 252 wire_protos.push_back(static_cast<uint8_t>(ch));
253 }
255 } 254 }
256 255
257 // Allocate memory for the result and fill it in.
258 std::vector<uint8_t> wire_protos;
259 wire_protos.reserve(wire_length);
260 for (const std::string& proto : next_proto_strings) {
261 wire_protos.push_back(proto.size());
262 // TODO(bnc): Rewrite.
263 wire_protos.resize(wire_protos.size() + proto.size());
264 memcpy(&wire_protos[wire_protos.size() - proto.size()], proto.data(),
265 proto.size());
266 }
267 DCHECK_EQ(wire_protos.size(), wire_length);
268
269 return wire_protos; 256 return wire_protos;
270 } 257 }
271 258
272 void SSLClientSocket::RecordNegotiationExtension() { 259 void SSLClientSocket::RecordNegotiationExtension() {
273 if (negotiation_extension_ == kExtensionUnknown) 260 if (negotiation_extension_ == kExtensionUnknown)
274 return; 261 return;
275 std::string proto; 262 std::string proto;
276 SSLClientSocket::NextProtoStatus status = GetNextProto(&proto); 263 SSLClientSocket::NextProtoStatus status = GetNextProto(&proto);
277 if (status == kNextProtoUnsupported) 264 if (status == kNextProtoUnsupported)
278 return; 265 return;
(...skipping 10 matching lines...) Expand all
289 } else { 276 } else {
290 sample += 500; 277 sample += 500;
291 } 278 }
292 } else { 279 } else {
293 DCHECK_EQ(kExtensionALPN, negotiation_extension_); 280 DCHECK_EQ(kExtensionALPN, negotiation_extension_);
294 } 281 }
295 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample); 282 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SSLProtocolNegotiation", sample);
296 } 283 }
297 284
298 } // namespace net 285 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698