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

Side by Side Diff: base/file_util.h

Issue 11782005: Don't allow path traversal paths on the base file helpers (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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 | base/file_util.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 // This file contains utility functions for dealing with the local 5 // This file contains utility functions for dealing with the local
6 // filesystem. 6 // filesystem.
7 7
8 #ifndef BASE_FILE_UTIL_H_ 8 #ifndef BASE_FILE_UTIL_H_
9 #define BASE_FILE_UTIL_H_ 9 #define BASE_FILE_UTIL_H_
10 10
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // otherwise. If either file can't be read, returns false. 169 // otherwise. If either file can't be read, returns false.
170 BASE_EXPORT bool ContentsEqual(const FilePath& filename1, 170 BASE_EXPORT bool ContentsEqual(const FilePath& filename1,
171 const FilePath& filename2); 171 const FilePath& filename2);
172 172
173 // Returns true if the contents of the two text files given are equal, false 173 // Returns true if the contents of the two text files given are equal, false
174 // otherwise. This routine treats "\r\n" and "\n" as equivalent. 174 // otherwise. This routine treats "\r\n" and "\n" as equivalent.
175 BASE_EXPORT bool TextContentsEqual(const FilePath& filename1, 175 BASE_EXPORT bool TextContentsEqual(const FilePath& filename1,
176 const FilePath& filename2); 176 const FilePath& filename2);
177 177
178 // Read the file at |path| into |contents|, returning true on success. 178 // Read the file at |path| into |contents|, returning true on success.
179 // This function fails if the |path| contains path traversal components ('..').
179 // |contents| may be NULL, in which case this function is useful for its 180 // |contents| may be NULL, in which case this function is useful for its
180 // side effect of priming the disk cache. 181 // side effect of priming the disk cache.
181 // Useful for unit tests. 182 // Useful for unit tests.
182 BASE_EXPORT bool ReadFileToString(const FilePath& path, std::string* contents); 183 BASE_EXPORT bool ReadFileToString(const FilePath& path, std::string* contents);
183 184
184 #if defined(OS_POSIX) 185 #if defined(OS_POSIX)
185 // Read exactly |bytes| bytes from file descriptor |fd|, storing the result 186 // Read exactly |bytes| bytes from file descriptor |fd|, storing the result
186 // in |buffer|. This function is protected against EINTR and partial reads. 187 // in |buffer|. This function is protected against EINTR and partial reads.
187 // Returns true iff |bytes| bytes have been successfuly read from |fd|. 188 // Returns true iff |bytes| bytes have been successfuly read from |fd|.
188 BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes); 189 BASE_EXPORT bool ReadFromFD(int fd, char* buffer, size_t bytes);
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 }; 620 };
620 621
621 // Attempts determine the FileSystemType for |path|. 622 // Attempts determine the FileSystemType for |path|.
622 // Returns false if |path| doesn't exist. 623 // Returns false if |path| doesn't exist.
623 BASE_EXPORT bool GetFileSystemType(const FilePath& path, FileSystemType* type); 624 BASE_EXPORT bool GetFileSystemType(const FilePath& path, FileSystemType* type);
624 #endif 625 #endif
625 626
626 } // namespace file_util 627 } // namespace file_util
627 628
628 #endif // BASE_FILE_UTIL_H_ 629 #endif // BASE_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698