[vfs] [dart] Ban opening empty path
ZX-3868 #done
Disallows opening with "" in the dart vfs.
Change-Id: I7a7a631266abac60c6397948ae57cd52f5133508
diff --git a/public/dart/fuchsia_vfs/lib/src/pseudo_dir.dart b/public/dart/fuchsia_vfs/lib/src/pseudo_dir.dart
index 0a942fd..e3a64da 100644
--- a/public/dart/fuchsia_vfs/lib/src/pseudo_dir.dart
+++ b/public/dart/fuchsia_vfs/lib/src/pseudo_dir.dart
@@ -129,7 +129,11 @@
@override
void open(
int flags, int mode, String path, fidl.InterfaceRequest<Node> request) {
- var p = path.trim();
+ if (path.startsWith('/') || path == '') {
+ sendErrorEvent(flags, ZX.ERR_BAD_PATH, request);
+ return;
+ }
+ var p = path;
// remove all ./, .//, etc
while (p.startsWith('./')) {
var index = 2;
@@ -139,12 +143,7 @@
p = p.substring(index);
}
- if (p.startsWith('/')) {
- sendErrorEvent(flags, ZX.ERR_BAD_PATH, request);
- return;
- }
-
- if (p == '' || p == '.') {
+ if (p == '.' || p == '') {
connect(flags, mode, request);
return;
}
diff --git a/public/dart/fuchsia_vfs/lib/src/vnode.dart b/public/dart/fuchsia_vfs/lib/src/vnode.dart
index ed879f9..d07c678 100644
--- a/public/dart/fuchsia_vfs/lib/src/vnode.dart
+++ b/public/dart/fuchsia_vfs/lib/src/vnode.dart
@@ -45,7 +45,6 @@
///
/// Vnode provides a simplified implementation for non-directory types.
/// Behavior:
- /// Bypasses to connect call for empty path and non-directory types.
/// For directory types, it will throw UnimplementedError error.
/// For non empty path it will fail with [ERR_NOT_DIR].
void open(int flags, int mode, String path, InterfaceRequest<Node> request) {
@@ -53,10 +52,6 @@
// dir types should implement this function
throw UnimplementedError();
}
- if (path == '') {
- connect(flags, mode, request);
- return;
- }
sendErrorEvent(flags, ZX.ERR_NOT_DIR, request);
}
diff --git a/public/dart/fuchsia_vfs/test/pseudo_dir_test.dart b/public/dart/fuchsia_vfs/test/pseudo_dir_test.dart
index be3117e..c7e82f3 100644
--- a/public/dart/fuchsia_vfs/test/pseudo_dir_test.dart
+++ b/public/dart/fuchsia_vfs/test/pseudo_dir_test.dart
@@ -722,7 +722,7 @@
PseudoDir dir = _setUpDir();
var proxy = _getProxyForDir(dir);
- var paths = ['.', '', './', './/', './//'];
+ var paths = ['.', './', './/', './//', './/.//./'];
for (var path in paths) {
DirectoryProxy newProxy = DirectoryProxy();
await proxy.open(0, 0, path,
@@ -745,6 +745,22 @@
}
});
+ test('open fails for empty path', () async {
+ PseudoDir dir = _setUpDir();
+
+ var proxy = _getProxyForDir(dir);
+ var newProxy = DirectoryProxy();
+ await proxy.open(openFlagDescribe, 0, '',
+ InterfaceRequest(newProxy.ctrl.request().passChannel()));
+
+ await newProxy.onOpen.first.then((response) {
+ expect(response.s, isNot(ZX.OK));
+ expect(response.info, isNull);
+ }).catchError((err) async {
+ fail(err.toString());
+ });
+ });
+
test('open file fails for path ending with "/"', () async {
PseudoDir dir = _setUpDir();
diff --git a/public/dart/fuchsia_vfs/test/pseudo_file_test.dart b/public/dart/fuchsia_vfs/test/pseudo_file_test.dart
index 11ff5c8..3618736 100644
--- a/public/dart/fuchsia_vfs/test/pseudo_file_test.dart
+++ b/public/dart/fuchsia_vfs/test/pseudo_file_test.dart
@@ -184,34 +184,22 @@
});
});
- test('open fails with non empty path', () async {
+ test('open fails', () async {
var file = _createReadWriteFileStub();
- var proxy = FileProxy();
- file.open(openRightReadable | openFlagDescribe, 0, '/',
- _getNodeInterfaceRequest(proxy));
+ var paths = ['', '/', '.', './', './/', './//'];
+ for (var path in paths) {
+ var proxy = FileProxy();
+ file.open(openRightReadable | openFlagDescribe, 0, path,
+ _getNodeInterfaceRequest(proxy));
- await proxy.onOpen.first.then((response) {
- expect(response.s, ZX.ERR_NOT_DIR);
- expect(response.info, isNull);
- }).catchError((err) async {
- fail(err.toString());
- });
- });
-
- test('open works with empty path', () async {
- var file = _createReadWriteFileStub();
-
- var proxy = FileProxy();
- file.open(openRightReadable | openFlagDescribe, 0, '',
- _getNodeInterfaceRequest(proxy));
-
- await proxy.onOpen.first.then((response) {
- expect(response.s, ZX.OK);
- expect(response.info, isNotNull);
- }).catchError((err) async {
- fail(err.toString());
- });
+ await proxy.onOpen.first.then((response) {
+ expect(response.s, ZX.ERR_NOT_DIR);
+ expect(response.info, isNull);
+ }).catchError((err) async {
+ fail(err.toString());
+ });
+ }
});
});