Skip to content

Commit

Permalink
src,permission: throw async errors on async APIs
Browse files Browse the repository at this point in the history
PR-URL: nodejs#52730
Refs: nodejs/security-wg#898
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
  • Loading branch information
RafaelGSS authored and eliphazbouye committed Jun 20, 2024
1 parent 81a81d1 commit e34edb4
Show file tree
Hide file tree
Showing 11 changed files with 420 additions and 260 deletions.
9 changes: 7 additions & 2 deletions src/node_dir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,24 @@ static void OpenDir(const FunctionCallbackInfo<Value>& args) {

BufferValue path(isolate, args[0]);
CHECK_NOT_NULL(*path);
THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());

const enum encoding encoding = ParseEncoding(isolate, args[1], UTF8);

FSReqBase* req_wrap_async = GetReqWrap(args, 2);
if (req_wrap_async != nullptr) { // openDir(path, encoding, req)
ASYNC_THROW_IF_INSUFFICIENT_PERMISSIONS(
env,
req_wrap_async,
permission::PermissionScope::kFileSystemRead,
path.ToStringView());
FS_DIR_ASYNC_TRACE_BEGIN1(
UV_FS_OPENDIR, req_wrap_async, "path", TRACE_STR_COPY(*path))
AsyncCall(env, req_wrap_async, args, "opendir", encoding, AfterOpenDir,
uv_fs_opendir, *path);
} else { // openDir(path, encoding, undefined, ctx)
CHECK_EQ(argc, 4);
THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());
FSReqWrapSync req_wrap_sync;
FS_DIR_SYNC_TRACE_BEGIN(opendir);
int result = SyncCall(env, args[3], &req_wrap_sync, "opendir",
Expand Down
Loading

0 comments on commit e34edb4

Please sign in to comment.