sec: Size function for helpers that return data with non-explicit size
authorPaul Kocialkowski <contact@paulk.fr>
Sun, 3 Aug 2014 09:10:50 +0000 (11:10 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Sun, 3 Aug 2014 09:10:50 +0000 (11:10 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
include/sec.h
samsung-ipc/sec.c

index 7a1d178..882b586 100644 (file)
@@ -173,6 +173,8 @@ int ipc_sec_phone_lock_request_set_setup(struct ipc_sec_phone_lock_request_set_d
 int ipc_sec_change_locking_pw_setup(struct ipc_sec_change_locking_pw_data *data,
     unsigned char facility_type, const char *password_old,
     const char *password_new);
+size_t ipc_sec_rsim_access_size_setup(struct ipc_sec_rsim_access_request_header *header,
+    const void *sim_io_data, size_t sim_io_size);
 void *ipc_sec_rsim_access_setup(struct ipc_sec_rsim_access_request_header *header,
     const void *sim_io_data, size_t sim_io_size);
 int ipc_sec_lock_infomation_setup(struct ipc_sec_lock_infomation_request_data *data,
index be5dccf..8ec633f 100644 (file)
@@ -120,6 +120,22 @@ int ipc_sec_change_locking_pw_setup(struct ipc_sec_change_locking_pw_data *data,
     return 0;
 }
 
+size_t ipc_sec_rsim_access_size_setup(struct ipc_sec_rsim_access_request_header *header,
+    const void *sim_io_data, size_t sim_io_size)
+{
+    size_t size;
+
+    if (header == NULL)
+        return 0;
+
+    if (sim_io_data == NULL)
+        sim_io_size = 0;
+
+    size = sizeof(struct ipc_sec_rsim_access_request_header) + sim_io_size;
+
+    return size;
+}
+
 void *ipc_sec_rsim_access_setup(struct ipc_sec_rsim_access_request_header *header,
     const void *sim_io_data, size_t sim_io_size)
 {
@@ -133,7 +149,9 @@ void *ipc_sec_rsim_access_setup(struct ipc_sec_rsim_access_request_header *heade
     if (sim_io_data == NULL)
         sim_io_size = 0;
 
-    size = sizeof(struct ipc_sec_rsim_access_request_header) + sim_io_size;
+    size = ipc_sec_rsim_access_size_setup(header, sim_io_data, sim_io_size);
+    if (size == 0)
+        return NULL;
 
     data = calloc(1, size);