You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@teaclave.apache.org by yu...@apache.org on 2025/11/17 07:25:22 UTC

(teaclave-trustzone-sdk) branch main updated: examples: change for acipher-rs (#255)

This is an automated email from the ASF dual-hosted git repository.

yuanz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/teaclave-trustzone-sdk.git


The following commit(s) were added to refs/heads/main by this push:
     new 23a041f  examples: change for acipher-rs (#255)
23a041f is described below

commit 23a041fd658c99f542e3ba83331784fbe8453819
Author: Matthew Shyu <47...@users.noreply.github.com>
AuthorDate: Mon Nov 17 15:25:18 2025 +0800

    examples: change for acipher-rs (#255)
    
    fix potential buffer overflow and match behavior with
    optee_examples
    
    Co-authored-by: Matthew Shyu <ma...@amlogic.com>
---
 examples/acipher-rs/proto/src/lib.rs | 2 +-
 examples/acipher-rs/ta/src/main.rs   | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/examples/acipher-rs/proto/src/lib.rs b/examples/acipher-rs/proto/src/lib.rs
index 86a211c..cbb31b9 100644
--- a/examples/acipher-rs/proto/src/lib.rs
+++ b/examples/acipher-rs/proto/src/lib.rs
@@ -22,9 +22,9 @@ use num_enum::{FromPrimitive, IntoPrimitive};
 #[repr(u32)]
 pub enum Command {
     GenKey,
-    GetSize,
     Encrypt,
     Decrypt,
+    GetSize,
     #[default]
     Unknown,
 }
diff --git a/examples/acipher-rs/ta/src/main.rs b/examples/acipher-rs/ta/src/main.rs
index 673cb64..f2537e3 100644
--- a/examples/acipher-rs/ta/src/main.rs
+++ b/examples/acipher-rs/ta/src/main.rs
@@ -97,8 +97,13 @@ fn encrypt(rsa: &mut RsaCipher, params: &mut Parameters) -> Result<()> {
             match cipher.encrypt(&[], plain_text) {
                 Err(e) => Err(e),
                 Ok(cipher_text) => {
-                    p1.buffer().clone_from_slice(&cipher_text);
-                    Ok(())
+                    if cipher_text.len() > p1.buffer().len() {
+                        p1.set_updated_size(cipher_text.len());
+                        Err(ErrorKind::ShortBuffer.into())
+                    } else {
+                        p1.buffer().clone_from_slice(&cipher_text);
+                        Ok(())
+                    }
                 }
             }
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@teaclave.apache.org
For additional commands, e-mail: commits-help@teaclave.apache.org