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

Unified Diff: pkg/analyzer/lib/file_system/physical_file_system.dart

Issue 2324513002: Issue 27243. Don't attempt to read Windows device drivers. (Closed)
Patch Set: Created 4 years, 3 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/file_system/physical_file_system.dart
diff --git a/pkg/analyzer/lib/file_system/physical_file_system.dart b/pkg/analyzer/lib/file_system/physical_file_system.dart
index 38fc38affe90e0764e4b8d1467a0b28a3a4d2d4a..ad430c0e7611d56a224bd47ae7e45778b9ea0b3e 100644
--- a/pkg/analyzer/lib/file_system/physical_file_system.dart
+++ b/pkg/analyzer/lib/file_system/physical_file_system.dart
@@ -152,6 +152,7 @@ class _PhysicalFile extends _PhysicalResource implements File {
@override
List<int> readAsBytesSync() {
+ _throwIfWindowsDeviceDriver();
try {
return _file.readAsBytesSync();
} on io.FileSystemException catch (exception) {
@@ -161,6 +162,7 @@ class _PhysicalFile extends _PhysicalResource implements File {
@override
String readAsStringSync() {
+ _throwIfWindowsDeviceDriver();
try {
return FileBasedSource.fileReadMode(_file.readAsStringSync());
} on io.FileSystemException catch (exception) {
@@ -351,6 +353,33 @@ abstract class _PhysicalResource implements Resource {
@override
String toString() => path;
+
+ /**
+ * If the operating system is Windows and the resource references one of the
+ * device drivers, throw a [FileSystemException].
+ *
+ * https://support.microsoft.com/en-us/kb/74496
+ */
+ void _throwIfWindowsDeviceDriver() {
+ if (io.Platform.isWindows) {
+ String shortName = this.shortName.toUpperCase();
+ if (shortName == r'CON' ||
+ shortName == r'PRN' ||
+ shortName == r'AUX' ||
+ shortName == r'CLOCK$' ||
+ shortName == r'NUL' ||
+ shortName == r'COM1' ||
+ shortName == r'LPT1' ||
+ shortName == r'LPT2' ||
+ shortName == r'LPT3' ||
+ shortName == r'COM2' ||
+ shortName == r'COM3' ||
+ shortName == r'COM4') {
+ throw new FileSystemException(
+ path, 'Windows device drivers cannot be read.');
+ }
+ }
+ }
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698