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 <algorithm> | 5 #include <algorithm> |
6 #include <iterator> | 6 #include <iterator> |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 { "application/x-mpegurl", "m3u8" }, | 109 { "application/x-mpegurl", "m3u8" }, |
110 }; | 110 }; |
111 | 111 |
112 const char* FindMimeType(const MimeInfo* mappings, | 112 const char* FindMimeType(const MimeInfo* mappings, |
113 size_t mappings_len, | 113 size_t mappings_len, |
114 const std::string& ext) { | 114 const std::string& ext) { |
115 for (size_t i = 0; i < mappings_len; ++i) { | 115 for (size_t i = 0; i < mappings_len; ++i) { |
116 const char* extensions = mappings[i].extensions; | 116 const char* extensions = mappings[i].extensions; |
117 for (;;) { | 117 for (;;) { |
118 size_t end_pos = strcspn(extensions, ","); | 118 size_t end_pos = strcspn(extensions, ","); |
| 119 // The length check is required to prevent the StringPiece below from |
| 120 // including uninitialized memory if ext is longer than extensions. |
119 if (end_pos == ext.size() && | 121 if (end_pos == ext.size() && |
120 base::strncasecmp(extensions, ext.data(), ext.size()) == 0) | 122 base::EqualsCaseInsensitiveASCII( |
| 123 base::StringPiece(extensions, ext.size()), ext)) |
121 return mappings[i].mime_type; | 124 return mappings[i].mime_type; |
122 extensions += end_pos; | 125 extensions += end_pos; |
123 if (!*extensions) | 126 if (!*extensions) |
124 break; | 127 break; |
125 extensions += 1; // skip over comma | 128 extensions += 1; // skip over comma |
126 } | 129 } |
127 } | 130 } |
128 return NULL; | 131 return NULL; |
129 } | 132 } |
130 | 133 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 std::string::size_type semicolon = mime_type_pattern.find(';'); | 264 std::string::size_type semicolon = mime_type_pattern.find(';'); |
262 const std::string base_pattern(mime_type_pattern.substr(0, semicolon)); | 265 const std::string base_pattern(mime_type_pattern.substr(0, semicolon)); |
263 semicolon = mime_type.find(';'); | 266 semicolon = mime_type.find(';'); |
264 const std::string base_type(mime_type.substr(0, semicolon)); | 267 const std::string base_type(mime_type.substr(0, semicolon)); |
265 | 268 |
266 if (base_pattern == "*" || base_pattern == "*/*") | 269 if (base_pattern == "*" || base_pattern == "*/*") |
267 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); | 270 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); |
268 | 271 |
269 const std::string::size_type star = base_pattern.find('*'); | 272 const std::string::size_type star = base_pattern.find('*'); |
270 if (star == std::string::npos) { | 273 if (star == std::string::npos) { |
271 if (base_pattern.size() == base_type.size() && | 274 if (base::EqualsCaseInsensitiveASCII(base_pattern, base_type)) |
272 base::strncasecmp(base_pattern.data(), base_type.data(), | |
273 base_pattern.size()) == 0) { | |
274 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); | 275 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); |
275 } else { | 276 else |
276 return false; | 277 return false; |
277 } | |
278 } | 278 } |
279 | 279 |
280 // Test length to prevent overlap between |left| and |right|. | 280 // Test length to prevent overlap between |left| and |right|. |
281 if (base_type.length() < base_pattern.length() - 1) | 281 if (base_type.length() < base_pattern.length() - 1) |
282 return false; | 282 return false; |
283 | 283 |
284 base::StringPiece base_pattern_piece(base_pattern); | 284 base::StringPiece base_pattern_piece(base_pattern); |
285 base::StringPiece left(base_pattern_piece.substr(0, star)); | 285 base::StringPiece left(base_pattern_piece.substr(0, star)); |
286 base::StringPiece right(base_pattern_piece.substr(star + 1)); | 286 base::StringPiece right(base_pattern_piece.substr(star + 1)); |
287 | 287 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 post_data->append("\r\n" + value + "\r\n"); | 580 post_data->append("\r\n" + value + "\r\n"); |
581 } | 581 } |
582 | 582 |
583 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 583 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
584 std::string* post_data) { | 584 std::string* post_data) { |
585 DCHECK(post_data); | 585 DCHECK(post_data); |
586 post_data->append("--" + mime_boundary + "--\r\n"); | 586 post_data->append("--" + mime_boundary + "--\r\n"); |
587 } | 587 } |
588 | 588 |
589 } // namespace net | 589 } // namespace net |
OLD | NEW |