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

Unified Diff: runtime/bin/file.cc

Issue 9427014: Disallow opening of directories as files. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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 | tests/standalone/src/FileTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file.cc
diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc
index 9eedc8579206a092f6931360747e25c844317c87..ed86895d24a95f229ebbbc07ee1a5e0e2b2d285b 100644
--- a/runtime/bin/file.cc
+++ b/runtime/bin/file.cc
@@ -59,7 +59,14 @@ void FUNCTION_NAME(File_Open)(Dart_NativeArguments args) {
if (mode == kAppend) {
file_mode = File::kWrite;
}
- File* file = File::Open(filename, file_mode);
+ // Check that the file exists before opening it only for
+ // reading. This is to prevent the opening of directories as
+ // files. Directories can be opened for reading using the posix
+ // 'open' call.
+ File* file = NULL;
+ if (((file_mode & File::kWrite) != 0) || File::Exists(filename)) {
+ file = File::Open(filename, file_mode);
+ }
Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file)));
Dart_ExitScope();
}
« no previous file with comments | « no previous file | tests/standalone/src/FileTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698