Skip to content

Commit

Permalink
Merge pull request #4679 from libraries/fix_inherited_fds
Browse files Browse the repository at this point in the history
fix(script): fixed panic when calling inherited_fds in root process
  • Loading branch information
zhangsoledad authored Oct 16, 2024
2 parents 248cfa8 + 3977b90 commit de1473e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
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

0 comments on commit de1473e

Please sign in to comment.