teaclave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ms...@apache.org
Subject [incubator-mesatee] branch master updated: Update mesapy to fix FNS/MesaPy FFI issues (#69)
Date Thu, 21 Nov 2019 23:55:29 GMT
This is an automated email from the ASF dual-hosted git repository.

mssun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mesatee.git


The following commit(s) were added to refs/heads/master by this push:
     new d506014  Update mesapy to fix FNS/MesaPy FFI issues (#69)
d506014 is described below

commit d506014613dd67c8b0098409575a9d5dd6cd4726
Author: Mingshen Sun <bob@mssun.me>
AuthorDate: Thu Nov 21 15:55:21 2019 -0800

    Update mesapy to fix FNS/MesaPy FFI issues (#69)
    
    * Update mesapy to fix FNS/MesaPy FFI issues
    
    * Check buffer len before save file
    
    * Fix style
---
 CMakeLists.txt                                     |  2 +-
 examples/py_file/data/1.txt                        | 54 +++++++++++++++++++++-
 examples/py_file/payload.py                        |  2 +-
 mesatee_services/fns/sgx_trusted_lib/src/global.rs | 35 ++++++++++----
 4 files changed, 80 insertions(+), 13 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4d6a0af..ceaf0c7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,7 +12,7 @@ SET_STRVAR_FROM_ENV_OR(SGX_SDK "/opt/sgxsdk" "Path of SGX SDK")
 SET_STRVAR_FROM_ENV_OR(SGX_MODE "HW" "Mode of SGX, HW or SW")
 SET_STRVAR_FROM_ENV_OR(RUSTFLAGS "" "Rust flags")
 SET_STRVAR_FROM_ENV_OR(MESATEE_CMAKE_DBG "" "set to turn on debug message for cmake")
-set(MESAPY_VERSION be21a3fa089832b27b817ef263b79a79ef3c8a6f CACHE STRING "mesapy version")
+set(MESAPY_VERSION 2b7ea38773d337d106c613a239661a60a4fa7528 CACHE STRING "mesapy version")
 option(COV OFF "Turn on coverage or not")
 # ======= VARIABLES FOR CMAKE -D{VAR}=VAL CONFIGURATION END =======
 
diff --git a/examples/py_file/data/1.txt b/examples/py_file/data/1.txt
index d383c56..a066467 100644
--- a/examples/py_file/data/1.txt
+++ b/examples/py_file/data/1.txt
@@ -1 +1,53 @@
-testdata
+Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
+incididunt ut labore et dolore magna aliqua. Lorem mollis aliquam ut porttitor
+leo a. Tristique risus nec feugiat in fermentum posuere urna. Facilisis leo vel
+fringilla est ullamcorper eget nulla. Purus in mollis nunc sed id semper risus.
+Arcu non odio euismod lacinia at quis risus sed vulputate. Non tellus orci ac
+auctor augue. Sed turpis tincidunt id aliquet. Nibh praesent tristique magna sit
+amet. Gravida dictum fusce ut placerat orci. Maecenas volutpat blandit aliquam
+etiam erat velit scelerisque. Leo vel orci porta non pulvinar neque. Ullamcorper
+sit amet risus nullam.
+
+Turpis egestas sed tempus urna et pharetra pharetra. Aliquet bibendum enim
+facilisis gravida. Ac turpis egestas integer eget aliquet. Et malesuada fames ac
+turpis egestas maecenas. Tempor orci eu lobortis elementum. Ultrices vitae
+auctor eu augue ut lectus arcu. In tellus integer feugiat scelerisque varius. Et
+pharetra pharetra massa massa ultricies mi quis hendrerit. Ornare arcu odio ut
+sem nulla pharetra diam sit amet. Hac habitasse platea dictumst vestibulum
+rhoncus. Porta lorem mollis aliquam ut porttitor leo a diam. Vel pretium lectus
+quam id. Sem fringilla ut morbi tincidunt augue interdum velit euismod in. Vel
+risus commodo viverra maecenas accumsan lacus vel facilisis. Sed arcu non odio
+euismod lacinia at quis risus sed. Quisque non tellus orci ac. Lacus luctus
+accumsan tortor posuere ac ut. Viverra maecenas accumsan lacus vel facilisis
+volutpat est velit. Quis commodo odio aenean sed adipiscing diam donec
+adipiscing. Phasellus egestas tellus rutrum tellus pellentesque eu tincidunt
+tortor aliquam.
+
+Scelerisque mauris pellentesque pulvinar pellentesque habitant morbi tristique
+senectus et. Sollicitudin tempor id eu nisl nunc mi. Dolor magna eget est lorem.
+Non tellus orci ac auctor augue mauris augue. Nibh venenatis cras sed felis eget
+velit. Feugiat pretium nibh ipsum consequat. Congue eu consequat ac felis donec
+et odio. Ultrices mi tempus imperdiet nulla malesuada pellentesque elit eget
+gravida. Vel facilisis volutpat est velit egestas. Euismod nisi porta lorem
+mollis aliquam ut porttitor leo a. Sollicitudin tempor id eu nisl nunc mi ipsum.
+
+Mi quis hendrerit dolor magna eget est lorem ipsum dolor. Viverra tellus in hac
+habitasse platea. Ultrices vitae auctor eu augue ut lectus. Malesuada fames ac
+turpis egestas sed tempus. Imperdiet proin fermentum leo vel orci porta non.
+Molestie at elementum eu facilisis. Maecenas volutpat blandit aliquam etiam.
+Quam lacus suspendisse faucibus interdum posuere. Suscipit adipiscing bibendum
+est ultricies integer. Interdum velit laoreet id donec.
+
+Venenatis a condimentum vitae sapien pellentesque habitant. Bibendum est
+ultricies integer quis auctor elit sed. Consectetur libero id faucibus nisl
+tincidunt eget nullam. Sit amet nisl purus in mollis nunc sed id. Ut venenatis
+tellus in metus vulputate. Vulputate eu scelerisque felis imperdiet proin
+fermentum leo vel. Tellus in metus vulputate eu scelerisque felis imperdiet
+proin. Aliquam sem fringilla ut morbi tincidunt augue interdum velit. Elit eget
+gravida cum sociis natoque penatibus et magnis dis. Neque ornare aenean euismod
+elementum nisi quis eleifend quam. Egestas sed sed risus pretium quam. Tristique
+risus nec feugiat in fermentum posuere urna. Ac turpis egestas integer eget
+aliquet nibh. In eu mi bibendum neque. Proin sed libero enim sed faucibus turpis
+in. In fermentum et sollicitudin ac orci phasellus egestas tellus rutrum. Neque
+laoreet suspendisse interdum consectetur libero id. Aliquam sem fringilla ut
+morbi tincidunt augue interdum. Massa id neque aliquam vestibulum morbi blandit.
diff --git a/examples/py_file/payload.py b/examples/py_file/payload.py
index 54a154a..18756f9 100644
--- a/examples/py_file/payload.py
+++ b/examples/py_file/payload.py
@@ -9,7 +9,7 @@ def save_file_for_task_creator(context_id, context_token):
 
 def read_file(context_id, context_token, file_id):
     content = mesatee.mesatee_read_file(context_id, context_token, file_id)
-    if content == "testdata\n": return True
+    if content.startswith("Lorem ipsum dolor sit amet"): return True
     else: return False
 
 def save_file_for_all_participants(context_id, context_token):
diff --git a/mesatee_services/fns/sgx_trusted_lib/src/global.rs b/mesatee_services/fns/sgx_trusted_lib/src/global.rs
index 64f7607..53d9859 100644
--- a/mesatee_services/fns/sgx_trusted_lib/src/global.rs
+++ b/mesatee_services/fns/sgx_trusted_lib/src/global.rs
@@ -28,13 +28,17 @@ use std::prelude::v1::*;
 
 use std::slice;
 
+const FFI_FILE_ERROR: c_int = -1;
+const FFI_BUFFER_NOT_ENOUGH_ERROR: c_int = -2;
+const UUID_SIZE: size_t = 36;
+
 // C API of read_file for workers
 //
 // int c_read_file(char* context_id,
 //                 char* context_token,
 //                 char* file_id,
 //                 char* out_buf,
-//                 size_t out_buf_size);
+//                 size_t* out_buf_size);
 #[allow(unused)]
 #[no_mangle]
 extern "C" fn c_read_file(
@@ -42,11 +46,12 @@ extern "C" fn c_read_file(
     context_token: *const c_char,
     file_id: *const c_char,
     out_buf: *mut u8,
-    out_buf_size: size_t,
+    out_buf_size_p: *mut size_t,
 ) -> c_int {
     let context_id = unsafe { CStr::from_ptr(context_id).to_string_lossy().into_owned() };
     let context_token = unsafe { CStr::from_ptr(context_token).to_string_lossy().into_owned()
};
     let file_id = unsafe { CStr::from_ptr(file_id).to_string_lossy().into_owned() };
+    let out_buf_size = unsafe { *out_buf_size_p };
     let out: &mut [u8] = unsafe { slice::from_raw_parts_mut(out_buf, out_buf_size) };
 
     match read_file(&context_id, &context_token, &file_id) {
@@ -56,10 +61,11 @@ extern "C" fn c_read_file(
                 out[..content.len()].copy_from_slice(&content);
                 content_len as c_int
             } else {
-                out_buf_size as c_int - content_len as c_int
+                unsafe { *out_buf_size_p = content_len }
+                FFI_BUFFER_NOT_ENOUGH_ERROR
             }
         }
-        Err(_) => 0,
+        Err(_) => FFI_FILE_ERROR,
     }
 }
 
@@ -81,6 +87,9 @@ extern "C" fn c_save_file_for_task_creator(
     out_file_id_buf: *mut u8,
     out_file_id_buf_size: size_t,
 ) -> c_int {
+    if out_file_id_buf_size < UUID_SIZE {
+        return FFI_BUFFER_NOT_ENOUGH_ERROR;
+    }
     let context_id = unsafe { CStr::from_ptr(context_id).to_string_lossy().into_owned() };
     let context_token = unsafe { CStr::from_ptr(context_token).to_string_lossy().into_owned()
};
     let in_buf: &[u8] = unsafe { slice::from_raw_parts(in_buf, in_buf_size) };
@@ -94,10 +103,10 @@ extern "C" fn c_save_file_for_task_creator(
                 out_file_id[..file_id_len].copy_from_slice(file_id.as_bytes());
                 file_id_len as c_int
             } else {
-                out_file_id_buf_size as c_int - file_id_len as c_int
+                FFI_BUFFER_NOT_ENOUGH_ERROR
             }
         }
-        Err(_) => 0,
+        Err(_) => FFI_FILE_ERROR,
     }
 }
 
@@ -119,6 +128,9 @@ extern "C" fn c_save_file_for_all_participants(
     out_file_id_buf: *mut u8,
     out_file_id_buf_size: size_t,
 ) -> c_int {
+    if out_file_id_buf_size < UUID_SIZE {
+        return FFI_BUFFER_NOT_ENOUGH_ERROR;
+    }
     let context_id = unsafe { CStr::from_ptr(context_id).to_string_lossy().into_owned() };
     let context_token = unsafe { CStr::from_ptr(context_token).to_string_lossy().into_owned()
};
     let in_buf: &[u8] = unsafe { slice::from_raw_parts(in_buf, in_buf_size) };
@@ -132,10 +144,10 @@ extern "C" fn c_save_file_for_all_participants(
                 out_file_id[..file_id_len].copy_from_slice(file_id.as_bytes());
                 file_id_len as c_int
             } else {
-                out_file_id_buf_size as c_int - file_id_len as c_int
+                FFI_BUFFER_NOT_ENOUGH_ERROR
             }
         }
-        Err(_) => 0,
+        Err(_) => FFI_FILE_ERROR,
     }
 }
 
@@ -159,6 +171,9 @@ extern "C" fn c_save_file_for_file_owner(
     out_file_id_buf: *mut u8,
     out_file_id_buf_size: size_t,
 ) -> c_int {
+    if out_file_id_buf_size < UUID_SIZE {
+        return FFI_BUFFER_NOT_ENOUGH_ERROR;
+    }
     let context_id = unsafe { CStr::from_ptr(context_id).to_string_lossy().into_owned() };
     let context_token = unsafe { CStr::from_ptr(context_token).to_string_lossy().into_owned()
};
     let in_buf: &[u8] = unsafe { slice::from_raw_parts(in_buf, in_buf_size) };
@@ -173,10 +188,10 @@ extern "C" fn c_save_file_for_file_owner(
                 out_file_id[..file_id_len].copy_from_slice(file_id.as_bytes());
                 file_id_len as c_int
             } else {
-                out_file_id_buf_size as c_int - file_id_len as c_int
+                FFI_BUFFER_NOT_ENOUGH_ERROR
             }
         }
-        Err(_) => 0,
+        Err(_) => FFI_FILE_ERROR,
     }
 }
 


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


Mime
View raw message