diff --git a/script/src/scheduler.rs b/script/src/scheduler.rs index 3c93c0ee82..358acda0e5 100644 --- a/script/src/scheduler.rs +++ b/script/src/scheduler.rs @@ -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, diff --git a/script/src/verify/tests/ckb_latest/features_since_v2023.rs b/script/src/verify/tests/ckb_latest/features_since_v2023.rs index e99dd32f5b..d5eb783ca0 100644 --- a/script/src/verify/tests/ckb_latest/features_since_v2023.rs +++ b/script/src/verify/tests/ckb_latest/features_since_v2023.rs @@ -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; diff --git a/script/testdata/spawn_cases b/script/testdata/spawn_cases index dbfddd345e..c4acb37967 100755 Binary files a/script/testdata/spawn_cases and b/script/testdata/spawn_cases differ diff --git a/script/testdata/spawn_cases.c b/script/testdata/spawn_cases.c index 43c8d96791..171164df03 100644 --- a/script/testdata/spawn_cases.c +++ b/script/testdata/spawn_cases.c @@ -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; @@ -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); }