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

Side by Side Diff: chrome/common/extensions/extension_resource.cc

Issue 11308204: Fix directory traversal in extension_resources.cc. Adds test case, which is complicated by several… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/extensions/extension_resource_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) 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 "chrome/common/extensions/extension_resource.h" 5 #include "chrome/common/extensions/extension_resource.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 10
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // path before resolving the symlink must still be within it. 60 // path before resolving the symlink must still be within it.
61 if (symlink_policy == FOLLOW_SYMLINKS_ANYWHERE) { 61 if (symlink_policy == FOLLOW_SYMLINKS_ANYWHERE) {
62 std::vector<FilePath::StringType> components; 62 std::vector<FilePath::StringType> components;
63 relative_path.GetComponents(&components); 63 relative_path.GetComponents(&components);
64 int depth = 0; 64 int depth = 0;
65 65
66 for (std::vector<FilePath::StringType>::const_iterator 66 for (std::vector<FilePath::StringType>::const_iterator
67 i = components.begin(); i != components.end(); i++) { 67 i = components.begin(); i != components.end(); i++) {
68 if (*i == FilePath::kParentDirectory) { 68 if (*i == FilePath::kParentDirectory) {
69 depth--; 69 depth--;
70 } else { 70 } else if (*i != FilePath::kCurrentDirectory) {
71 depth++; 71 depth++;
72 } 72 }
73 if (depth < 0) { 73 if (depth < 0) {
74 return FilePath(); 74 return FilePath();
75 } 75 }
76 } 76 }
77 } 77 }
78 78
79 // We must resolve the absolute path of the combined path when 79 // We must resolve the absolute path of the combined path when
80 // the relative path contains references to a parent folder (i.e., '..'). 80 // the relative path contains references to a parent folder (i.e., '..').
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // Make sure we have a cached value to test against... 112 // Make sure we have a cached value to test against...
113 if (full_resource_path_.empty()) 113 if (full_resource_path_.empty())
114 GetFilePath(); 114 GetFilePath();
115 if (NormalizeSeperators(path.value()) == 115 if (NormalizeSeperators(path.value()) ==
116 NormalizeSeperators(full_resource_path_.value())) { 116 NormalizeSeperators(full_resource_path_.value())) {
117 return true; 117 return true;
118 } else { 118 } else {
119 return false; 119 return false;
120 } 120 }
121 } 121 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/extension_resource_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698