From 6a2e2bfbabde5a411f224a06a54ec6fef37b2d6b Mon Sep 17 00:00:00 2001 From: hyc23373070 Date: Mon, 1 Jun 2026 20:11:19 +0800 Subject: [PATCH 1/2] fix:add null pointer checks in PLuginMethod invoke --- crates/xtee-teec/src/extension.rs | 35 ++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/crates/xtee-teec/src/extension.rs b/crates/xtee-teec/src/extension.rs index 8f50b49..75c5315 100644 --- a/crates/xtee-teec/src/extension.rs +++ b/crates/xtee-teec/src/extension.rs @@ -33,6 +33,39 @@ pub struct PluginMethod { ) -> raw::TEEC_Result, } +// --- Begin of added safe wrapper --- +impl PluginMethod { + /// Safely invoke the plugin method with null pointer checks. + /// + /// This function validates critical pointers before calling the unsafe `invoke`. + /// It returns `TEEC_ERROR_BAD_PARAMETERS` if any required pointer is null: + /// - `self.name` is null (invalid plugin method) + /// - `out_len` is null (cannot report output length) + /// - `data` is null while `in_len` is non-zero (input buffer required) + /// + /// After validation, it forwards the call to the original `invoke` function. + pub fn invoke_checked( + &self, + cmd: u32, + sub_cmd: u32, + data: *mut c_char, + in_len: u32, + out_len: *mut u32, + ) -> raw::TEEC_Result { + if self.name.is_null() { + return raw::TEEC_ERROR_BAD_PARAMETERS; + } + if out_len.is_null() { + return raw::TEEC_ERROR_BAD_PARAMETERS; + } + if data.is_null() && in_len != 0 { + return raw::TEEC_ERROR_BAD_PARAMETERS; + } + unsafe { (self.invoke)(cmd, sub_cmd, data, in_len, out_len) } + } +} +// --- End of added safe wrapper --- + /// struct PluginParameters { /// @cmd: u32, plugin cmd, defined in proto/ /// @sub_cmd: u32, plugin subcmd, defined in proto/ @@ -76,4 +109,4 @@ impl<'a> PluginParameters<'a> { pub fn get_required_out_len(&self) -> usize { self.required_outlen } -} +} \ No newline at end of file -- Gitee From 0dbce94b20b6db0421df02617173ab2985e5701a Mon Sep 17 00:00:00 2001 From: hyc23373070 Date: Tue, 9 Jun 2026 22:01:31 +0800 Subject: [PATCH 2/2] fix:add null pointer checks in PluginMethod invoke --- crates/xtee-teec/src/extension.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/crates/xtee-teec/src/extension.rs b/crates/xtee-teec/src/extension.rs index 75c5315..f3383cc 100644 --- a/crates/xtee-teec/src/extension.rs +++ b/crates/xtee-teec/src/extension.rs @@ -33,17 +33,8 @@ pub struct PluginMethod { ) -> raw::TEEC_Result, } -// --- Begin of added safe wrapper --- + impl PluginMethod { - /// Safely invoke the plugin method with null pointer checks. - /// - /// This function validates critical pointers before calling the unsafe `invoke`. - /// It returns `TEEC_ERROR_BAD_PARAMETERS` if any required pointer is null: - /// - `self.name` is null (invalid plugin method) - /// - `out_len` is null (cannot report output length) - /// - `data` is null while `in_len` is non-zero (input buffer required) - /// - /// After validation, it forwards the call to the original `invoke` function. pub fn invoke_checked( &self, cmd: u32, @@ -64,7 +55,7 @@ impl PluginMethod { unsafe { (self.invoke)(cmd, sub_cmd, data, in_len, out_len) } } } -// --- End of added safe wrapper --- + /// struct PluginParameters { /// @cmd: u32, plugin cmd, defined in proto/ -- Gitee