DemesneGH commented on code in PR #253:
URL:
https://github.com/apache/teaclave-trustzone-sdk/pull/253#discussion_r2509357002
##########
examples/serde-rs/ta/src/main.rs:
##########
@@ -52,18 +55,26 @@ fn invoke_command(cmd_id: u32, params: &mut Parameters) ->
Result<()> {
match Command::from(cmd_id) {
Command::DefaultOp => {
let mut p = unsafe { params.0.as_memref()? };
- let mut buffer = p.buffer();
+ let buffer = p.buffer();
let point = Point { x: 1, y: 2 };
// Convert the Point to a JSON string.
- let serialized = serde_json::to_string(&point).map_err(|e| {
+ let serialized: String = serde_json::to_string(&point).map_err(|e|
{
trace_println!("Failed to serialize point: {}", e);
ErrorKind::BadParameters
})?;
- let len = buffer.write(serialized.as_bytes()).map_err(|e| {
- trace_println!("Failed to write to buffer: {}", e);
- ErrorKind::BadParameters
- })?;
+
+ let bytes = serialized.as_bytes();
+
+ // Ensure the buffer is large enough to hold the serialized data.
+ if bytes.len() > buffer.len() {
+ trace_println!("Buffer too small, cannot copy all bytes");
+ return Err(ErrorKind::BadParameters.into());
+ }
+
+ // Copy the serialized JSON string into the buffer.
+ let len = bytes.len();
+ buffer[..len].copy_from_slice(bytes);
// update size of output buffer
unsafe { (*p.raw()).size = len };
Review Comment:
Please also help to correct this line, should use the `set_updated_size()`
https://github.com/apache/teaclave-trustzone-sdk/blob/main/optee-utee/src/parameter.rs#L89C12-L89C28
--
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]