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

Side by Side Diff: net/base/escape.cc

Issue 408: Fix an out of band read when parsing a URL component of just "%". The... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 3 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
« no previous file with comments | « no previous file | net/base/escape_unittest.cc » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "net/base/escape.h" 7 #include "net/base/escape.h"
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 }; 106 };
107 107
108 std::string UnescapeURLImpl(const std::string& escaped_text, 108 std::string UnescapeURLImpl(const std::string& escaped_text,
109 UnescapeRule::Type rules) { 109 UnescapeRule::Type rules) {
110 // The output of the unescaping is always smaller than the input, so we can 110 // The output of the unescaping is always smaller than the input, so we can
111 // reserve the input size to make sure we have enough buffer and don't have 111 // reserve the input size to make sure we have enough buffer and don't have
112 // to allocate in the loop below. 112 // to allocate in the loop below.
113 std::string result; 113 std::string result;
114 result.reserve(escaped_text.length()); 114 result.reserve(escaped_text.length());
115 115
116 for (size_t i = 0, max = escaped_text.size(), max_digit_index = max - 2; 116 for (size_t i = 0, max = escaped_text.size(); i < max; ++i) {
117 i < max; ++i) { 117 if (escaped_text[i] == '%' && i + 2 < max) {
118 if (escaped_text[i] == '%' && i < max_digit_index) {
119 const std::string::value_type most_sig_digit(escaped_text[i + 1]); 118 const std::string::value_type most_sig_digit(escaped_text[i + 1]);
120 const std::string::value_type least_sig_digit(escaped_text[i + 2]); 119 const std::string::value_type least_sig_digit(escaped_text[i + 2]);
121 if (IsHex(most_sig_digit) && IsHex(least_sig_digit)) { 120 if (IsHex(most_sig_digit) && IsHex(least_sig_digit)) {
122 unsigned char value = HexToInt(most_sig_digit) * 16 + 121 unsigned char value = HexToInt(most_sig_digit) * 16 +
123 HexToInt(least_sig_digit); 122 HexToInt(least_sig_digit);
124 if (value >= 0x80 || // Unescape all high-bit characters. 123 if (value >= 0x80 || // Unescape all high-bit characters.
125 // For 7-bit characters, the lookup table tells us all valid chars. 124 // For 7-bit characters, the lookup table tells us all valid chars.
126 (kUrlUnescape[value] || 125 (kUrlUnescape[value] ||
127 // ...and we allow some additional unescaping when flags are set. 126 // ...and we allow some additional unescaping when flags are set.
128 (value == ' ' && (rules & UnescapeRule::SPACES)) || 127 (value == ' ' && (rules & UnescapeRule::SPACES)) ||
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 276 }
278 277
279 std::string EscapeForHTML(const std::string& input) { 278 std::string EscapeForHTML(const std::string& input) {
280 return EscapeForHTMLImpl(input); 279 return EscapeForHTMLImpl(input);
281 } 280 }
282 281
283 std::wstring EscapeForHTML(const std::wstring& input) { 282 std::wstring EscapeForHTML(const std::wstring& input) {
284 return EscapeForHTMLImpl(input); 283 return EscapeForHTMLImpl(input);
285 } 284 }
286 285
OLDNEW
« no previous file with comments | « no previous file | net/base/escape_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698