1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(cli/ops/net): add write permissions for unixpackets datagrams & unix socket (#8511)

Fixes #7781
This commit is contained in:
William Perron 2020-11-27 13:43:39 -05:00 committed by GitHub
parent ff3c5897ea
commit 59f10b3604
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 1 deletions

View file

@ -229,7 +229,7 @@ async fn op_datagram_send(
let address_path = Path::new(&args.path); let address_path = Path::new(&args.path);
{ {
let s = state.borrow(); let s = state.borrow();
s.borrow::<Permissions>().check_read(&address_path)?; s.borrow::<Permissions>().check_write(&address_path)?;
} }
let mut state = state.borrow_mut(); let mut state = state.borrow_mut();
let resource = state let resource = state
@ -308,6 +308,7 @@ async fn op_connect(
{ {
let state_ = state.borrow(); let state_ = state.borrow();
state_.borrow::<Permissions>().check_read(&address_path)?; state_.borrow::<Permissions>().check_read(&address_path)?;
state_.borrow::<Permissions>().check_write(&address_path)?;
} }
let path = args.path; let path = args.path;
let unix_stream = net_unix::UnixStream::connect(Path::new(&path)).await?; let unix_stream = net_unix::UnixStream::connect(Path::new(&path)).await?;

View file

@ -65,6 +65,44 @@ unitTest(
}, },
); );
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true } },
function netUnixListenWritePermission(): void {
try {
const filePath = Deno.makeTempFileSync();
const socket = Deno.listen({
path: filePath,
transport: "unix",
});
assert(socket.addr.transport === "unix");
assertEquals(socket.addr.path, filePath);
socket.close();
} catch (e) {
assert(!!e);
assert(e instanceof Deno.errors.PermissionDenied);
}
},
);
unitTest(
{ ignore: Deno.build.os === "windows", perms: { read: true } },
function netUnixPacketListenWritePermission(): void {
try {
const filePath = Deno.makeTempFileSync();
const socket = Deno.listenDatagram({
path: filePath,
transport: "unixpacket",
});
assert(socket.addr.transport === "unixpacket");
assertEquals(socket.addr.path, filePath);
socket.close();
} catch (e) {
assert(!!e);
assert(e instanceof Deno.errors.PermissionDenied);
}
},
);
unitTest( unitTest(
{ {
perms: { net: true }, perms: { net: true },