GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: fix chown abort · nodejs/node@8598745

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/fs
    • promises.js
  • src
    • node_file.cc
  • test/parallel
    • test-fs-promises.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/fs/promises.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/promises.js
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const kIoMaxLength = 2 ** 31 - 1;
99
const kReadFileMaxChunkSize = 2 ** 14;
1010
const kWriteFileMaxChunkSize = 2 ** 14;
1111

12+
// 2 ** 32 - 1
13+
const kMaxUserId = 4294967295;
14+
1215
const {
1316
Error,
1417
MathMax,
@@ -66,7 +69,6 @@ const {
6669
validateAbortSignal,
6770
validateBuffer,
6871
validateInteger,
69-
validateUint32
7072
} = require('internal/validators');
7173
const pathModule = require('path');
7274
const { promisify } = require('internal/util');
@@ -580,22 +582,22 @@ async function lchmod(path, mode) {
580582

581583
async function lchown(path, uid, gid) {
582584
path = getValidatedPath(path);
583-
validateUint32(uid, 'uid');
584-
validateUint32(gid, 'gid');
585+
validateInteger(uid, 'uid', -1, kMaxUserId);
586+
validateInteger(gid, 'gid', -1, kMaxUserId);
585587
return binding.lchown(pathModule.toNamespacedPath(path),
586588
uid, gid, kUsePromises);
587589
}
588590

589591
async function fchown(handle, uid, gid) {
590-
validateUint32(uid, 'uid');
591-
validateUint32(gid, 'gid');
592+
validateInteger(uid, 'uid', -1, kMaxUserId);
593+
validateInteger(gid, 'gid', -1, kMaxUserId);
592594
return binding.fchown(handle.fd, uid, gid, kUsePromises);
593595
}
594596

595597
async function chown(path, uid, gid) {
596598
path = getValidatedPath(path);
597-
validateUint32(uid, 'uid');
598-
validateUint32(gid, 'gid');
599+
validateInteger(uid, 'uid', -1, kMaxUserId);
600+
validateInteger(gid, 'gid', -1, kMaxUserId);
599601
return binding.chown(pathModule.toNamespacedPath(path),
600602
uid, gid, kUsePromises);
601603
}
Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
+12-13Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ using v8::ObjectTemplate;
6969
using v8::Promise;
7070
using v8::String;
7171
using v8::Symbol;
72-
using v8::Uint32;
7372
using v8::Undefined;
7473
using v8::Value;
7574

@@ -2178,11 +2177,11 @@ static void Chown(const FunctionCallbackInfo<Value>& args) {
21782177
BufferValue path(env->isolate(), args[0]);
21792178
CHECK_NOT_NULL(*path);
21802179

2181-
CHECK(args[1]->IsUint32());
2182-
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value());
2180+
CHECK(IsSafeJsInt(args[1]));
2181+
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value());
21832182

2184-
CHECK(args[2]->IsUint32());
2185-
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Uint32>()->Value());
2183+
CHECK(IsSafeJsInt(args[2]));
2184+
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value());
21862185

21872186
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
21882187
if (req_wrap_async != nullptr) { // chown(path, uid, gid, req)
@@ -2211,11 +2210,11 @@ static void FChown(const FunctionCallbackInfo<Value>& args) {
22112210
CHECK(args[0]->IsInt32());
22122211
const int fd = args[0].As<Int32>()->Value();
22132212

2214-
CHECK(args[1]->IsUint32());
2215-
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value());
2213+
CHECK(IsSafeJsInt(args[1]));
2214+
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value());
22162215

2217-
CHECK(args[2]->IsUint32());
2218-
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Uint32>()->Value());
2216+
CHECK(IsSafeJsInt(args[2]));
2217+
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value());
22192218

22202219
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
22212220
if (req_wrap_async != nullptr) { // fchown(fd, uid, gid, req)
@@ -2241,11 +2240,11 @@ static void LChown(const FunctionCallbackInfo<Value>& args) {
22412240
BufferValue path(env->isolate(), args[0]);
22422241
CHECK_NOT_NULL(*path);
22432242

2244-
CHECK(args[1]->IsUint32());
2245-
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value());
2243+
CHECK(IsSafeJsInt(args[1]));
2244+
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value());
22462245

2247-
CHECK(args[2]->IsUint32());
2248-
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Uint32>()->Value());
2246+
CHECK(IsSafeJsInt(args[2]));
2247+
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value());
22492248

22502249
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
22512250
if (req_wrap_async != nullptr) { // lchown(path, uid, gid, req)
Collapse file

‎test/parallel/test-fs-promises.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-promises.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,24 @@ async function getHandle(dest) {
183183

184184
assert.rejects(
185185
async () => {
186-
await chown(dest, 1, -1);
186+
await chown(dest, 1, -2);
187187
},
188188
{
189189
code: 'ERR_OUT_OF_RANGE',
190190
name: 'RangeError',
191191
message: 'The value of "gid" is out of range. ' +
192-
'It must be >= 0 && < 4294967296. Received -1'
192+
'It must be >= -1 && <= 4294967295. Received -2'
193193
});
194194

195195
assert.rejects(
196196
async () => {
197-
await handle.chown(1, -1);
197+
await handle.chown(1, -2);
198198
},
199199
{
200200
code: 'ERR_OUT_OF_RANGE',
201201
name: 'RangeError',
202202
message: 'The value of "gid" is out of range. ' +
203-
'It must be >= 0 && < 4294967296. Received -1'
203+
'It must be >= -1 && <= 4294967295. Received -2'
204204
});
205205

206206
await handle.close();

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.