-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(process): add process.initgroups(user, group) implementation #27902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2845,9 +2845,52 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionsetgroups, (JSGlobalObject * globalObje | |||||
| return JSValue::encode(jsNumber(result)); | ||||||
| } | ||||||
|
|
||||||
| JSC_DEFINE_HOST_FUNCTION(Process_functionInitgroups, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) | ||||||
| { | ||||||
| auto& vm = JSC::getVM(globalObject); | ||||||
| auto scope = DECLARE_THROW_SCOPE(vm); | ||||||
|
|
||||||
| if (callFrame->argumentCount() < 2) { | ||||||
| return Bun::ERR::MISSING_ARGS(scope, globalObject, "user, group"_s, 2, callFrame->argumentCount()); | ||||||
| } | ||||||
|
|
||||||
| auto userValue = callFrame->argument(0); | ||||||
| auto groupValue = callFrame->argument(1); | ||||||
|
|
||||||
| // Convert user to string | ||||||
| Bun::V::validateString(scope, globalObject, userValue, "user"_s, jsUndefined()); | ||||||
| RETURN_IF_EXCEPTION(scope, {}); | ||||||
| auto userStr = userValue.toWTFString(globalObject); | ||||||
| RETURN_IF_EXCEPTION(scope, {}); | ||||||
|
|
||||||
| // Convert group to gid_t | ||||||
| gid_t group; | ||||||
| if (groupValue.isNumber()) { | ||||||
| Bun::V::validateUint32(scope, globalObject, groupValue, "group"_s, jsUndefined()); | ||||||
| RETURN_IF_EXCEPTION(scope, {}); | ||||||
| group = groupValue.toUInt32(globalObject); | ||||||
| } else if (groupValue.isString()) { | ||||||
| auto resolvedGroup = maybe_gid_by_name(scope, globalObject, groupValue); | ||||||
| RETURN_IF_EXCEPTION(scope, {}); | ||||||
| group = resolvedGroup.toUInt32(globalObject); | ||||||
| } else { | ||||||
| return Bun::ERR::INVALID_ARG_TYPE(scope, globalObject, "group"_s, "number or string"_s, groupValue); | ||||||
| } | ||||||
|
|
||||||
| // Call initgroups | ||||||
| auto result = initgroups(userStr.utf8().data(), group); | ||||||
| if (result != 0) { | ||||||
| throwSystemError(scope, globalObject, "initgroups"_s, errno); | ||||||
| return {}; | ||||||
| } | ||||||
|
|
||||||
| RETURN_IF_EXCEPTION(scope, {}); | ||||||
| return JSValue::encode(jsUndefined()); | ||||||
| } | ||||||
|
|
||||||
| #endif | ||||||
|
|
||||||
| JSC_DEFINE_HOST_FUNCTION(Process_functionAssert, (JSGlobalObject * globalObject, CallFrame* callFrame)) | ||||||
| JSC_DEFINE_HOST_FUNCTION(Process_functionAssert, (JSC::JSGlobalObject * globalObject, CallFrame* callFrame)) | ||||||
| { | ||||||
| auto& vm = JSC::getVM(globalObject); | ||||||
| auto throwScope = DECLARE_THROW_SCOPE(vm); | ||||||
|
|
@@ -4051,6 +4094,7 @@ extern "C" void Process__emitErrorEvent(Zig::GlobalObject* global, EncodedJSValu | |||||
| seteuid Process_functionseteuid Function 1 | ||||||
| setgid Process_functionsetgid Function 1 | ||||||
| setgroups Process_functionsetgroups Function 1 | ||||||
| initgroups Process_functionInitgroups Function 1 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify Node.js process.initgroups.length is 2
node -e "console.log('process.initgroups.length:', process.initgroups.length)"Repository: oven-sh/bun Length of output: 83 🏁 Script executed: # Check if the file exists and read the relevant lines
file_path="src/bun.js/bindings/BunProcess.cpp"
if [ -f "$file_path" ]; then
echo "=== Line 4097 (LUT entry) ==="
sed -n '4095,4099p' "$file_path"
echo ""
echo "=== Lines 2853-2855 (enforcement check) ==="
sed -n '2851,2857p' "$file_path"
else
echo "File not found: $file_path"
fiRepository: oven-sh/bun Length of output: 773 Incorrect function length in LUT entry. The 🔧 Proposed fix- initgroups Process_functionInitgroups Function 1
+ initgroups Process_functionInitgroups Function 2📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| setuid Process_functionsetuid Function 1 | ||||||
| #endif | ||||||
| @end | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Redundant exception check after error return.
Line 2887
RETURN_IF_EXCEPTION(scope, {});is unreachable. Ifinitgroupsfails, the exception is thrown at line 2883 and the function returns at line 2884. Ifinitgroupssucceeds, no exception is pending. This line can be safely removed.🧹 Proposed cleanup
auto result = initgroups(userStr.utf8().data(), group); if (result != 0) { throwSystemError(scope, globalObject, "initgroups"_s, errno); return {}; } - RETURN_IF_EXCEPTION(scope, {}); return JSValue::encode(jsUndefined()); }📝 Committable suggestion
🤖 Prompt for AI Agents