GeezerVison is showing github.com — fs: fix chown abort · nodejs/node@8598745
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/fs/promises.js +9-7Lines changed: 9 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,9 @@ const kIoMaxLength = 2 ** 31 - 1; | 9 | 9 | const kReadFileMaxChunkSize = 2 ** 14; | 10 | 10 | const kWriteFileMaxChunkSize = 2 ** 14; | 11 | 11 |
| | 12 | +// 2 ** 32 - 1 | | 13 | +const kMaxUserId = 4294967295; | | 14 | + | 12 | 15 | const { | 13 | 16 | Error, | 14 | 17 | MathMax, | @@ -66,7 +69,6 @@ const { | 66 | 69 | validateAbortSignal, | 67 | 70 | validateBuffer, | 68 | 71 | validateInteger, | 69 | | - validateUint32 | 70 | 72 | } = require('internal/validators'); | 71 | 73 | const pathModule = require('path'); | 72 | 74 | const { promisify } = require('internal/util'); | @@ -580,22 +582,22 @@ async function lchmod(path, mode) { | 580 | 582 |
| 581 | 583 | async function lchown(path, uid, gid) { | 582 | 584 | path = getValidatedPath(path); | 583 | | - validateUint32(uid, 'uid'); | 584 | | - validateUint32(gid, 'gid'); | | 585 | + validateInteger(uid, 'uid', -1, kMaxUserId); | | 586 | + validateInteger(gid, 'gid', -1, kMaxUserId); | 585 | 587 | return binding.lchown(pathModule.toNamespacedPath(path), | 586 | 588 | uid, gid, kUsePromises); | 587 | 589 | } | 588 | 590 |
| 589 | 591 | 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); | 592 | 594 | return binding.fchown(handle.fd, uid, gid, kUsePromises); | 593 | 595 | } | 594 | 596 |
| 595 | 597 | async function chown(path, uid, gid) { | 596 | 598 | path = getValidatedPath(path); | 597 | | - validateUint32(uid, 'uid'); | 598 | | - validateUint32(gid, 'gid'); | | 599 | + validateInteger(uid, 'uid', -1, kMaxUserId); | | 600 | + validateInteger(gid, 'gid', -1, kMaxUserId); | 599 | 601 | return binding.chown(pathModule.toNamespacedPath(path), | 600 | 602 | uid, gid, kUsePromises); | 601 | 603 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/node_file.cc +12-13Lines changed: 12 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -69,7 +69,6 @@ using v8::ObjectTemplate; | 69 | 69 | using v8::Promise; | 70 | 70 | using v8::String; | 71 | 71 | using v8::Symbol; | 72 | | -using v8::Uint32; | 73 | 72 | using v8::Undefined; | 74 | 73 | using v8::Value; | 75 | 74 |
| @@ -2178,11 +2177,11 @@ static void Chown(const FunctionCallbackInfo<Value>& args) { | 2178 | 2177 | BufferValue path(env->isolate(), args[0]); | 2179 | 2178 | CHECK_NOT_NULL(*path); | 2180 | 2179 |
| 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()); | 2183 | 2182 |
| 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()); | 2186 | 2185 |
| 2187 | 2186 | FSReqBase* req_wrap_async = GetReqWrap(args, 3); | 2188 | 2187 | if (req_wrap_async != nullptr) { // chown(path, uid, gid, req) | @@ -2211,11 +2210,11 @@ static void FChown(const FunctionCallbackInfo<Value>& args) { | 2211 | 2210 | CHECK(args[0]->IsInt32()); | 2212 | 2211 | const int fd = args[0].As<Int32>()->Value(); | 2213 | 2212 |
| 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()); | 2216 | 2215 |
| 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()); | 2219 | 2218 |
| 2220 | 2219 | FSReqBase* req_wrap_async = GetReqWrap(args, 3); | 2221 | 2220 | if (req_wrap_async != nullptr) { // fchown(fd, uid, gid, req) | @@ -2241,11 +2240,11 @@ static void LChown(const FunctionCallbackInfo<Value>& args) { | 2241 | 2240 | BufferValue path(env->isolate(), args[0]); | 2242 | 2241 | CHECK_NOT_NULL(*path); | 2243 | 2242 |
| 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()); | 2246 | 2245 |
| 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()); | 2249 | 2248 |
| 2250 | 2249 | FSReqBase* req_wrap_async = GetReqWrap(args, 3); | 2251 | 2250 | if (req_wrap_async != nullptr) { // lchown(path, uid, gid, req) | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-promises.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -183,24 +183,24 @@ async function getHandle(dest) { | 183 | 183 |
| 184 | 184 | assert.rejects( | 185 | 185 | async () => { | 186 | | - await chown(dest, 1, -1); | | 186 | + await chown(dest, 1, -2); | 187 | 187 | }, | 188 | 188 | { | 189 | 189 | code: 'ERR_OUT_OF_RANGE', | 190 | 190 | name: 'RangeError', | 191 | 191 | 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' | 193 | 193 | }); | 194 | 194 |
| 195 | 195 | assert.rejects( | 196 | 196 | async () => { | 197 | | - await handle.chown(1, -1); | | 197 | + await handle.chown(1, -2); | 198 | 198 | }, | 199 | 199 | { | 200 | 200 | code: 'ERR_OUT_OF_RANGE', | 201 | 201 | name: 'RangeError', | 202 | 202 | 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' | 204 | 204 | }); | 205 | 205 |
| 206 | 206 | await handle.close(); | |
|