Skip to content

Commit 0b1ac96

Browse files
RafaelGSSaduh95
authored andcommitted
src: handle duplicate paths granted
This commit fixes a crash whenever someone tries to allow access to the same path twice. PR-URL: #56591 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 13bdd9c commit 0b1ac96

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/permission/fs_permission.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ void FSPermission::Apply(Environment* env,
143143

144144
void FSPermission::GrantAccess(PermissionScope perm, const std::string& res) {
145145
const std::string path = WildcardIfDir(res);
146-
if (perm == PermissionScope::kFileSystemRead) {
146+
if (perm == PermissionScope::kFileSystemRead &&
147+
!granted_in_fs_.Lookup(path)) {
147148
granted_in_fs_.Insert(path);
148149
deny_all_in_ = false;
149-
} else if (perm == PermissionScope::kFileSystemWrite) {
150+
} else if (perm == PermissionScope::kFileSystemWrite &&
151+
!granted_out_fs_.Lookup(path)) {
150152
granted_out_fs_.Insert(path);
151153
deny_all_out_ = false;
152154
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Flags: --permission --allow-fs-read=* --allow-child-process
2+
'use strict';
3+
4+
const common = require('../common');
5+
const path = require('path');
6+
common.skipIfWorker();
7+
8+
const assert = require('assert');
9+
const { spawnSync } = require('child_process');
10+
11+
{
12+
// Relative path as CLI args are supported
13+
const { status, stdout } = spawnSync(
14+
process.execPath,
15+
[
16+
'--permission',
17+
'--allow-fs-write', path.resolve('../fixtures/permission/deny/regular-file.md'),
18+
'--allow-fs-write', path.resolve('../fixtures/permission/deny/regular-file.md'),
19+
'--allow-fs-read', path.resolve('../fixtures/permission/deny/regular-file.md'),
20+
'--allow-fs-read', path.resolve('../fixtures/permission/deny/regular-file.md'),
21+
'-e',
22+
`
23+
const path = require("path");
24+
const absolutePath = path.resolve("../fixtures/permission/deny/regular-file.md");
25+
const blockedPath = path.resolve("../fixtures/permission/deny/protected-file.md");
26+
console.log(process.permission.has("fs.write", absolutePath));
27+
console.log(process.permission.has("fs.read", absolutePath));
28+
console.log(process.permission.has("fs.read", blockedPath));
29+
console.log(process.permission.has("fs.write", blockedPath));
30+
`,
31+
]
32+
);
33+
34+
const [fsWrite, fsRead, fsBlockedRead, fsBlockedWrite] = stdout.toString().split('\n');
35+
assert.strictEqual(status, 0);
36+
assert.strictEqual(fsWrite, 'true');
37+
assert.strictEqual(fsRead, 'true');
38+
assert.strictEqual(fsBlockedRead, 'false');
39+
assert.strictEqual(fsBlockedWrite, 'false');
40+
}

0 commit comments

Comments
 (0)