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

Unified Diff: base/file_util.h

Issue 254333002: Make base::ReadFileToString() return false on I/O error. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix EXPECT_EQ() parameter order. Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/file_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util.h
diff --git a/base/file_util.h b/base/file_util.h
index 7ca2d38968e52c66eb0b470046116e71352eec5c..ca7bf626ba48b6ced4a687e50401f726ade3c2c4 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -136,22 +136,24 @@ BASE_EXPORT bool ContentsEqual(const FilePath& filename1,
BASE_EXPORT bool TextContentsEqual(const FilePath& filename1,
const FilePath& filename2);
-// Reads the file at |path| into |contents| and returns true on success.
-// |contents| may be NULL, in which case this function is useful for its
-// side effect of priming the disk cache (could be used for unit tests).
-// The function returns false and the string pointed to by |contents| is
-// cleared when |path| does not exist or if it contains path traversal
-// components ('..').
+// Reads the file at |path| into |contents| and returns true on success and
+// false on error. For security reasons, a |path| containing path traversal
+// components ('..') is treated as a read error and |contents| is set to empty.
+// In case of I/O error, |contents| holds the data that could be read from the
+// file before the error occurred.
+// |contents| may be NULL, in which case this function is useful for its side
+// effect of priming the disk cache (could be used for unit tests).
BASE_EXPORT bool ReadFileToString(const FilePath& path, std::string* contents);
-// Reads the file at |path| into |contents| and returns true on success.
-// |contents| may be NULL, in which case this function is useful for its
-// side effect of priming the disk cache (could be used for unit tests).
-// The function returns false and the string pointed to by |contents| is
-// cleared when |path| does not exist or if it contains path traversal
-// components ('..').
-// When the file size exceeds |max_size|, the function returns false
-// with |contents| holding the file truncated to |max_size|.
+// Reads the file at |path| into |contents| and returns true on success and
+// false on error. For security reasons, a |path| containing path traversal
+// components ('..') is treated as a read error and |contents| is set to empty.
+// In case of I/O error, |contents| holds the data that could be read from the
+// file before the error occurred. When the file size exceeds |max_size|, the
+// function returns false with |contents| holding the file truncated to
+// |max_size|.
+// |contents| may be NULL, in which case this function is useful for its side
+// effect of priming the disk cache (could be used for unit tests).
BASE_EXPORT bool ReadFileToString(const FilePath& path,
std::string* contents,
size_t max_size);
@@ -172,7 +174,7 @@ BASE_EXPORT bool CreateSymbolicLink(const FilePath& target,
// Returns false upon failure.
BASE_EXPORT bool ReadSymbolicLink(const FilePath& symlink, FilePath* target);
-// Bits ans masks of the file permission.
+// Bits and masks of the file permission.
enum FilePermissionBits {
FILE_PERMISSION_MASK = S_IRWXU | S_IRWXG | S_IRWXO,
FILE_PERMISSION_USER_MASK = S_IRWXU,
« 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