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

Side by Side Diff: extensions/browser/file_highlighter.cc

Issue 23875013: Handle invalid input for SourceHighlighter, Don't Allow Relative Paths in ErrorHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove comment + address security risk in ErrorHandler Created 7 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
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 "extensions/browser/file_highlighter.h" 5 #include "extensions/browser/file_highlighter.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 SourceHighlighter::SourceHighlighter(const std::string& contents, 196 SourceHighlighter::SourceHighlighter(const std::string& contents,
197 size_t line_number) 197 size_t line_number)
198 : FileHighlighter(contents) { 198 : FileHighlighter(contents) {
199 Parse(line_number); 199 Parse(line_number);
200 } 200 }
201 201
202 SourceHighlighter::~SourceHighlighter() { 202 SourceHighlighter::~SourceHighlighter() {
203 } 203 }
204 204
205 void SourceHighlighter::Parse(size_t line_number) { 205 void SourceHighlighter::Parse(size_t line_number) {
206 for (size_t i = 1; i < line_number; ++i) 206 // If line 0 is requested, highlight nothing.
207 start_ = contents_.find('\n', start_) + 1; 207 if (line_number == 0) {
208 start_ = contents_.size();
209 return;
210 }
211
212 for (size_t i = 1; i < line_number; ++i) {
213 start_ = contents_.find('\n', start_);
214 if (start_ == std::string::npos)
215 break;
216 start_ += 1;
217 }
218
208 end_ = contents_.find('\n', start_); 219 end_ = contents_.find('\n', start_);
209 220
210 // If we went off the end of the string (i.e., the line number was invalid), 221 // If we went off the end of the string (i.e., the line number was invalid),
211 // then move start and end to the end of the string, so that the highlighted 222 // then move start and end to the end of the string, so that the highlighted
212 // portion is empty. 223 // portion is empty.
213 start_ = start_ == std::string::npos ? contents_.size() : start_; 224 start_ = start_ == std::string::npos ? contents_.size() : start_;
214 end_ = end_ == std::string::npos ? contents_.size() : end_; 225 end_ = end_ == std::string::npos ? contents_.size() : end_;
215 } 226 }
216 227
217 } // namespace extensions 228 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/extensions/extension_error_handler.cc ('k') | extensions/browser/file_highlighter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698