Skip to content
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

Backport #4679, fix(script): fixed panic when calling inherited_fds in root process #4681

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion script/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,11 @@ where
);
}
Message::InheritedFileDescriptor(vm_id, args) => {
let inherited_fd = self.inherited_fd[&vm_id].clone();
let inherited_fd = if vm_id == ROOT_VM_ID {
Vec::new()
} else {
self.inherited_fd[&vm_id].clone()
};
let (_, machine) = self.ensure_get_instantiated(&vm_id)?;
let FdArgs {
buffer_addr,
Expand Down
6 changes: 6 additions & 0 deletions script/src/verify/tests/ckb_latest/features_since_v2023.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,12 @@ fn check_spawn_index_out_of_bound() {
assert_eq!(result.is_ok(), SCRIPT_VERSION == ScriptVersion::V2);
}

#[test]
fn check_root_inherited_fds() {
let result = simple_spawn_test("testdata/spawn_cases", &[19]);
assert_eq!(result.is_ok(), SCRIPT_VERSION == ScriptVersion::V2);
}

#[test]
fn check_spawn_cycles() {
let script_version = SCRIPT_VERSION;
Expand Down
Binary file modified script/testdata/spawn_cases
Binary file not shown.
13 changes: 13 additions & 0 deletions script/testdata/spawn_cases.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,17 @@ int parent_index_out_of_bound(uint64_t* pid) {
return err;
}

int parent_root_inherited_fds() {
uint64_t fds[2] = {0};
uint64_t length = 2;
int err = ckb_inherited_fds(fds, &length);
CHECK(err);
CHECK2(length == 0, -1);
err = 0;
exit:
return err;
}

int parent_entry(int case_id) {
int err = 0;
uint64_t pid = 0;
Expand Down Expand Up @@ -577,6 +588,8 @@ int parent_entry(int case_id) {
return parent_invaild_index(&pid);
} else if (case_id == 18) {
return parent_index_out_of_bound(&pid);
} else if (case_id == 19) {
return parent_root_inherited_fds();
} else {
CHECK2(false, -2);
}
Expand Down
Loading