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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/standalone/src/FileTest.dart » ('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 Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/file.h" 5 #include "bin/file.h"
6 6
7 #include "bin/builtin.h" 7 #include "bin/builtin.h"
8 #include "bin/dartutils.h" 8 #include "bin/dartutils.h"
9 9
10 #include "include/dart_api.h" 10 #include "include/dart_api.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 52 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
53 int mode = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1)); 53 int mode = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 1));
54 ASSERT(mode == kRead || mode == kWrite || mode == kAppend); 54 ASSERT(mode == kRead || mode == kWrite || mode == kAppend);
55 File::FileOpenMode file_mode = File::kRead; 55 File::FileOpenMode file_mode = File::kRead;
56 if (mode == kWrite) { 56 if (mode == kWrite) {
57 file_mode = File::kWriteTruncate; 57 file_mode = File::kWriteTruncate;
58 } 58 }
59 if (mode == kAppend) { 59 if (mode == kAppend) {
60 file_mode = File::kWrite; 60 file_mode = File::kWrite;
61 } 61 }
62 File* file = File::Open(filename, file_mode); 62 // Check that the file exists before opening it only for
63 // reading. This is to prevent the opening of directories as
64 // files. Directories can be opened for reading using the posix
65 // 'open' call.
66 File* file = NULL;
67 if (((file_mode & File::kWrite) != 0) || File::Exists(filename)) {
68 file = File::Open(filename, file_mode);
69 }
63 Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file))); 70 Dart_SetReturnValue(args, Dart_NewInteger(reinterpret_cast<intptr_t>(file)));
64 Dart_ExitScope(); 71 Dart_ExitScope();
65 } 72 }
66 73
67 74
68 void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) { 75 void FUNCTION_NAME(File_Exists)(Dart_NativeArguments args) {
69 Dart_EnterScope(); 76 Dart_EnterScope();
70 const char* filename = 77 const char* filename =
71 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0)); 78 DartUtils::GetStringValue(Dart_GetNativeArgument(args, 0));
72 bool exists = File::Exists(filename); 79 bool exists = File::Exists(filename);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 } 342 }
336 343
337 344
338 void FUNCTION_NAME(File_GetStdioHandleType)(Dart_NativeArguments args) { 345 void FUNCTION_NAME(File_GetStdioHandleType)(Dart_NativeArguments args) {
339 Dart_EnterScope(); 346 Dart_EnterScope();
340 int fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); 347 int fd = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0));
341 File::StdioHandleType type = File::GetStdioHandleType(fd); 348 File::StdioHandleType type = File::GetStdioHandleType(fd);
342 Dart_SetReturnValue(args, Dart_NewInteger(type)); 349 Dart_SetReturnValue(args, Dart_NewInteger(type));
343 Dart_ExitScope(); 350 Dart_ExitScope();
344 } 351 }
OLDNEW
« 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