Skip to content

Commit

Permalink
fix(cli/ops/net): add write permissions for unixpackets datagrams & u…
Browse files Browse the repository at this point in the history
…nix socket (denoland#8511)

Fixes denoland#7781
  • Loading branch information
wperron authored Nov 27, 2020
1 parent ff3c589 commit 59f10b3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cli/ops/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ async fn op_datagram_send(
let address_path = Path::new(&args.path);
{
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 resource = state
Expand Down Expand Up @@ -308,6 +308,7 @@ async fn op_connect(
{
let state_ = state.borrow();
state_.borrow::<Permissions>().check_read(&address_path)?;
state_.borrow::<Permissions>().check_write(&address_path)?;
}
let path = args.path;
let unix_stream = net_unix::UnixStream::connect(Path::new(&path)).await?;
Expand Down
38 changes: 38 additions & 0 deletions cli/tests/unit/net_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
perms: { net: true },
Expand Down

0 comments on commit 59f10b3

Please sign in to comment.