DemesneGH commented on code in PR #254:
URL: 
https://github.com/apache/teaclave-trustzone-sdk/pull/254#discussion_r2522374990


##########
examples/message_passing_interface-rs/ta/Makefile:
##########
@@ -47,3 +57,5 @@ sign: strip
 
 clean:
        @cargo clean
+

Review Comment:
   Remove the extra empty lines



##########
examples/message_passing_interface-rs/ta/src/main.rs:
##########
@@ -71,21 +74,27 @@ fn invoke_command(cmd_id: u32, params: &mut Parameters) -> 
Result<()> {
     let mut p1 = unsafe { params.1.as_memref()? };
     let mut p2 = unsafe { params.2.as_value()? };
 
-    let input: proto::EnclaveInput = 
proto::serde_json::from_slice(p0.buffer()).map_err(|e| {
+    let input: proto::EnclaveInput = 
serde_json::from_slice(p0.buffer()).map_err(|e| {
         trace_println!("Failed to deserialize input: {}", e);
         ErrorKind::BadFormat
     })?;
     let output = handle_invoke(Command::from(cmd_id), input)?;
 
-    let output_vec = proto::serde_json::to_vec(&output).map_err(|e| {
+    let output_vec = serde_json::to_vec(&output).map_err(|e| {
         trace_println!("Failed to serialize output: {}", e);
         ErrorKind::BadFormat
     })?;
-    p1.buffer().write_all(&output_vec).map_err(|e| {
-        trace_println!("Failed to write output: {}", e);
-        ErrorKind::BadParameters
-    })?;
-    p2.set_a(output_vec.len() as u32);
+
+    let len = output_vec.len();
+    if len > p1.buffer().len() {
+        trace_println!("Buffer too small, cannot copy all bytes");
+        return Err(ErrorKind::BadParameters.into());
+    }
+
+    p1.buffer()[..len].copy_from_slice(&output_vec);
+    p1.set_updated_size(len);
+
+    p2.set_a(len as u32);

Review Comment:
   Remove the p2 from both ta and host, it makes sense to use 
`p1.set_updated_size(len);` to return the length.



-- 
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