DemesneGH commented on PR #235:
URL: 
https://github.com/apache/teaclave-trustzone-sdk/pull/235#issuecomment-3344773830

   Revert to previous commit because I have not yet found a good API design. 
Please see the 
https://github.com/apache/teaclave-trustzone-sdk/pull/235/commits for review.
   
   > The latest API change has side affect that causes panic in certain calling 
sequence, which could be avoided with a more elegant impl.
   > 
   > ```
   > #[cfg(test)]
   > mod tests {
   >     use super::*;
   > 
   >     #[test]
   >     fn test_set_buf_from_slice_overflow() {
   >         let mut buffer = [0u8; 8];
   >         let mut params = PluginParameters::new(1, 2, &mut buffer);
   > 
   >         let data = [1u8; 16];
   >         let result = params.set_buf_from_slice(&data);
   >         let s = params.get_out_slice();
   >         assert!(result.is_err());
   >     }
   > }
   > 
   > thread 'tests::test_set_buf_from_slice_overflow' panicked at ...:
   > range end index 16 out of range for slice of length 8
   > ```
   
   Workarounds for the potential issue:
   
   - Removed `get_out_slice()`. This function was originally used in legacy 
macro code and is no longer needed after the macro updates. Also, since plugins 
(as callees) only need to set output data, there is no need to read it back.
   
   - Renamed `outlen` to `required_outlen` for clarity.
   
   - Added documentation for `set_buf_from_slice()`, reminding developers to 
properly handle the result.
   
   Maybe we can change 
   `pub fn set_buf_from_slice(&mut self, sendslice: &[u8]) -> Result<()> ` to 
`pub fn set_buf_from_slice(&mut self, sendslice: &[u8]) -> (Result<()>, usize) 
` , 
   and `fn inner(#params) -> optee_teec::Result<()>` to `fn inner(#params) -> 
(optee_teec::Result<()>, usize)` to raise the Error with the `required_outlen`, 
but it needs further design and discussion.
   
   As this PR mainly addresses `cargo clippy` checks, we can merge it as-is and 
revisit the plugin API refinement in a future PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to