| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ce14080 commit ad7e344
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,9 @@ const kReadFileBufferLength = 512 * 1024; | |||
| 8 | 8 | const kReadFileUnknownBufferLength = 64 * 1024; | |
| 9 | 9 | const kWriteFileMaxChunkSize = 512 * 1024; | |
| 10 | 10 | ||
| 11 | + // 2 ** 32 - 1 | ||
| 12 | + const kMaxUserId = 4294967295; | ||
| 13 | + | ||
| 11 | 14 | const { | |
| 12 | 15 | ArrayPrototypePush, | |
| 13 | 16 | Error, | |
@@ -71,7 +74,6 @@ const { | |||
| 71 | 74 | validateBoolean, | |
| 72 | 75 | validateBuffer, | |
| 73 | 76 | validateInteger, | |
| 74 | - validateUint32 | ||
| 75 | 77 | } = require('internal/validators'); | |
| 76 | 78 | const pathModule = require('path'); | |
| 77 | 79 | const { promisify } = require('internal/util'); | |
@@ -615,22 +617,22 @@ async function lchmod(path, mode) { | |||
| 615 | 617 | ||
| 616 | 618 | async function lchown(path, uid, gid) { | |
| 617 | 619 | path = getValidatedPath(path); | |
| 618 | - validateUint32(uid, 'uid'); | ||
| 619 | - validateUint32(gid, 'gid'); | ||
| 620 | + validateInteger(uid, 'uid', -1, kMaxUserId); | ||
| 621 | + validateInteger(gid, 'gid', -1, kMaxUserId); | ||
| 620 | 622 | return binding.lchown(pathModule.toNamespacedPath(path), | |
| 621 | 623 | uid, gid, kUsePromises); | |
| 622 | 624 | } | |
| 623 | 625 | ||
| 624 | 626 | async function fchown(handle, uid, gid) { | |
| 625 | - validateUint32(uid, 'uid'); | ||
| 626 | - validateUint32(gid, 'gid'); | ||
| 627 | + validateInteger(uid, 'uid', -1, kMaxUserId); | ||
| 628 | + validateInteger(gid, 'gid', -1, kMaxUserId); | ||
| 627 | 629 | return binding.fchown(handle.fd, uid, gid, kUsePromises); | |
| 628 | 630 | } | |
| 629 | 631 | ||
| 630 | 632 | async function chown(path, uid, gid) { | |
| 631 | 633 | path = getValidatedPath(path); | |
| 632 | - validateUint32(uid, 'uid'); | ||
| 633 | - validateUint32(gid, 'gid'); | ||
| 634 | + validateInteger(uid, 'uid', -1, kMaxUserId); | ||
| 635 | + validateInteger(gid, 'gid', -1, kMaxUserId); | ||
| 634 | 636 | return binding.chown(pathModule.toNamespacedPath(path), | |
| 635 | 637 | uid, gid, kUsePromises); | |
| 636 | 638 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,7 +71,6 @@ using v8::ObjectTemplate; | |||
| 71 | 71 | using v8::Promise; | |
| 72 | 72 | using v8::String; | |
| 73 | 73 | using v8::Symbol; | |
| 74 | - using v8::Uint32; | ||
| 75 | 74 | using v8::Undefined; | |
| 76 | 75 | using v8::Value; | |
| 77 | 76 | ||
@@ -2184,11 +2183,11 @@ static void Chown(const FunctionCallbackInfo<Value>& args) { | |||
| 2184 | 2183 | BufferValue path(env->isolate(), args[0]); | |
| 2185 | 2184 | CHECK_NOT_NULL(*path); | |
| 2186 | 2185 | ||
| 2187 | - CHECK(args[1]->IsUint32()); | ||
| 2188 | - const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value()); | ||
| 2186 | + CHECK(IsSafeJsInt(args[1])); | ||
| 2187 | + const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value()); | ||
| 2189 | 2188 | ||
| 2190 | - CHECK(args[2]->IsUint32()); | ||
| 2191 | - const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Uint32>()->Value()); | ||
| 2189 | + CHECK(IsSafeJsInt(args[2])); | ||
| 2190 | + const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value()); | ||
| 2192 | 2191 | ||
| 2193 | 2192 | FSReqBase* req_wrap_async = GetReqWrap(args, 3); | |
| 2194 | 2193 | if (req_wrap_async != nullptr) { // chown(path, uid, gid, req) | |
@@ -2217,11 +2216,11 @@ static void FChown(const FunctionCallbackInfo<Value>& args) { | |||
| 2217 | 2216 | CHECK(args[0]->IsInt32()); | |
| 2218 | 2217 | const int fd = args[0].As<Int32>()->Value(); | |
| 2219 | 2218 | ||
| 2220 | - CHECK(args[1]->IsUint32()); | ||
| 2221 | - const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value()); | ||
| 2219 | + CHECK(IsSafeJsInt(args[1])); | ||
| 2220 | + const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value()); | ||
| 2222 | 2221 | ||
| 2223 | - CHECK(args[2]->IsUint32()); | ||
| 2224 | - const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Uint32>()->Value()); | ||
| 2222 | + CHECK(IsSafeJsInt(args[2])); | ||
| 2223 | + const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value()); | ||
| 2225 | 2224 | ||
| 2226 | 2225 | FSReqBase* req_wrap_async = GetReqWrap(args, 3); | |
| 2227 | 2226 | if (req_wrap_async != nullptr) { // fchown(fd, uid, gid, req) | |
@@ -2247,11 +2246,11 @@ static void LChown(const FunctionCallbackInfo<Value>& args) { | |||
| 2247 | 2246 | BufferValue path(env->isolate(), args[0]); | |
| 2248 | 2247 | CHECK_NOT_NULL(*path); | |
| 2249 | 2248 | ||
| 2250 | - CHECK(args[1]->IsUint32()); | ||
| 2251 | - const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value()); | ||
| 2249 | + CHECK(IsSafeJsInt(args[1])); | ||
| 2250 | + const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value()); | ||
| 2252 | 2251 | ||
| 2253 | - CHECK(args[2]->IsUint32()); | ||
| 2254 | - const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Uint32>()->Value()); | ||
| 2252 | + CHECK(IsSafeJsInt(args[2])); | ||
| 2253 | + const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value()); | ||
| 2255 | 2254 | ||
| 2256 | 2255 | FSReqBase* req_wrap_async = GetReqWrap(args, 3); | |
| 2257 | 2256 | if (req_wrap_async != nullptr) { // lchown(path, uid, gid, req) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -191,24 +191,24 @@ async function getHandle(dest) { | |||
| 191 | 191 | ||
| 192 | 192 | assert.rejects( | |
| 193 | 193 | async () => { | |
| 194 | - await chown(dest, 1, -1); | ||
| 194 | + await chown(dest, 1, -2); | ||
| 195 | 195 | }, | |
| 196 | 196 | { | |
| 197 | 197 | code: 'ERR_OUT_OF_RANGE', | |
| 198 | 198 | name: 'RangeError', | |
| 199 | 199 | message: 'The value of "gid" is out of range. ' + | |
| 200 | - 'It must be >= 0 && < 4294967296. Received -1' | ||
| 200 | + 'It must be >= -1 && <= 4294967295. Received -2' | ||
| 201 | 201 | }); | |
| 202 | 202 | ||
| 203 | 203 | assert.rejects( | |
| 204 | 204 | async () => { | |
| 205 | - await handle.chown(1, -1); | ||
| 205 | + await handle.chown(1, -2); | ||
| 206 | 206 | }, | |
| 207 | 207 | { | |
| 208 | 208 | code: 'ERR_OUT_OF_RANGE', | |
| 209 | 209 | name: 'RangeError', | |
| 210 | 210 | message: 'The value of "gid" is out of range. ' + | |
| 211 | - 'It must be >= 0 && < 4294967296. Received -1' | ||
| 211 | + 'It must be >= -1 && <= 4294967295. Received -2' | ||
| 212 | 212 | }); | |
| 213 | 213 | ||
| 214 | 214 | await handle.close(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments