OLD | NEW |
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/base/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 SanitizeGeneratedFileName(&sanitized, true); | 1145 SanitizeGeneratedFileName(&sanitized, true); |
1146 base::FilePath::StringType extension = component.Extension(); | 1146 base::FilePath::StringType extension = component.Extension(); |
1147 if (!extension.empty()) | 1147 if (!extension.empty()) |
1148 extension.erase(extension.begin()); // Erase preceding '.'. | 1148 extension.erase(extension.begin()); // Erase preceding '.'. |
1149 return !component.empty() && | 1149 return !component.empty() && |
1150 (component == component.BaseName()) && | 1150 (component == component.BaseName()) && |
1151 (component == component.StripTrailingSeparators()) && | 1151 (component == component.StripTrailingSeparators()) && |
1152 FilePathToString16(component, &component16) && | 1152 FilePathToString16(component, &component16) && |
1153 file_util::IsFilenameLegal(component16) && | 1153 file_util::IsFilenameLegal(component16) && |
1154 !IsShellIntegratedExtension(extension) && | 1154 !IsShellIntegratedExtension(extension) && |
1155 (sanitized == component.value()); | 1155 (sanitized == component.value()) && |
1156 } | 1156 !IsReservedName(component.value()); |
1157 | |
1158 bool IsSafePortableBasename(const base::FilePath& filename) { | |
1159 return IsSafePortablePathComponent(filename) && | |
1160 !IsReservedName(filename.value()); | |
1161 } | 1157 } |
1162 | 1158 |
1163 bool IsSafePortableRelativePath(const base::FilePath& path) { | 1159 bool IsSafePortableRelativePath(const base::FilePath& path) { |
1164 if (path.empty() || path.IsAbsolute() || path.EndsWithSeparator()) | 1160 if (path.empty() || path.IsAbsolute() || path.EndsWithSeparator()) |
1165 return false; | 1161 return false; |
1166 std::vector<base::FilePath::StringType> components; | 1162 std::vector<base::FilePath::StringType> components; |
1167 path.GetComponents(&components); | 1163 path.GetComponents(&components); |
1168 if (components.empty()) | 1164 if (components.empty()) |
1169 return false; | 1165 return false; |
1170 for (size_t i = 0; i < components.size() - 1; ++i) { | 1166 for (size_t i = 0; i < components.size() - 1; ++i) { |
1171 if (!IsSafePortablePathComponent(base::FilePath(components[i]))) | 1167 if (!IsSafePortablePathComponent(base::FilePath(components[i]))) |
1172 return false; | 1168 return false; |
1173 } | 1169 } |
1174 return IsSafePortableBasename(path.BaseName()); | 1170 return IsSafePortablePathComponent(path.BaseName()); |
1175 } | 1171 } |
1176 | 1172 |
1177 void GenerateSafeFileName(const std::string& mime_type, | 1173 void GenerateSafeFileName(const std::string& mime_type, |
1178 bool ignore_extension, | 1174 bool ignore_extension, |
1179 base::FilePath* file_path) { | 1175 base::FilePath* file_path) { |
1180 // Make sure we get the right file extension | 1176 // Make sure we get the right file extension |
1181 EnsureSafeExtension(mime_type, ignore_extension, file_path); | 1177 EnsureSafeExtension(mime_type, ignore_extension, file_path); |
1182 | 1178 |
1183 #if defined(OS_WIN) | 1179 #if defined(OS_WIN) |
1184 // Prepend "_" to the file name if it's a reserved name | 1180 // Prepend "_" to the file name if it's a reserved name |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2161 | 2157 |
2162 NetworkInterface::NetworkInterface(const std::string& name, | 2158 NetworkInterface::NetworkInterface(const std::string& name, |
2163 const IPAddressNumber& address) | 2159 const IPAddressNumber& address) |
2164 : name(name), address(address) { | 2160 : name(name), address(address) { |
2165 } | 2161 } |
2166 | 2162 |
2167 NetworkInterface::~NetworkInterface() { | 2163 NetworkInterface::~NetworkInterface() { |
2168 } | 2164 } |
2169 | 2165 |
2170 } // namespace net | 2166 } // namespace net |
OLD | NEW |