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

Side by Side Diff: net/der/input.cc

Issue 1160643002: Remove dangerous std::string constructor for der::Input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove FromCString; use uint8_t array literals instead of string literals now Created 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <string.h> 5 #include <string.h>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/der/input.h" 8 #include "net/der/input.h"
9 9
10 namespace net { 10 namespace net {
11 11
12 namespace der { 12 namespace der {
13 13
14 Input::Input() : data_(nullptr), len_(0) { 14 Input::Input() : data_(nullptr), len_(0) {
15 } 15 }
16 16
17 Input::Input(const uint8_t* data, size_t len) : data_(data), len_(len) { 17 Input::Input(const uint8_t* data, size_t len) : data_(data), len_(len) {
18 } 18 }
19 19
20 Input::Input(const std::string& s)
21 : data_(reinterpret_cast<const uint8_t*>(s.data())), len_(s.size()) {
22 }
23
24 bool Input::Equals(const Input& other) const { 20 bool Input::Equals(const Input& other) const {
25 if (len_ != other.len_) 21 if (len_ != other.len_)
26 return false; 22 return false;
27 return memcmp(data_, other.data_, len_) == 0; 23 return memcmp(data_, other.data_, len_) == 0;
28 } 24 }
29 25
30 ByteReader::ByteReader(const Input& in) 26 ByteReader::ByteReader(const Input& in)
31 : data_(in.UnsafeData()), len_(in.Length()) { 27 : data_(in.UnsafeData()), len_(in.Length()) {
32 } 28 }
33 29
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 87
92 Mark::Mark(const uint8_t* ptr) : ptr_(ptr) { 88 Mark::Mark(const uint8_t* ptr) : ptr_(ptr) {
93 } 89 }
94 90
95 Mark::Mark() : ptr_(nullptr) { 91 Mark::Mark() : ptr_(nullptr) {
96 } 92 }
97 93
98 } // namespace der 94 } // namespace der
99 95
100 } // namespace net 96 } // namespace net
OLDNEW
« no previous file with comments | « net/der/input.h ('k') | net/der/input_unittest.cc » ('j') | net/der/parse_values_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698