[Cryptech-Commits] [sw/libhal] 03/03: Shake dumb compile-time bugs out of new logout code.

git at cryptech.is git at cryptech.is
Tue May 23 04:27:03 UTC 2017


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch logout
in repository sw/libhal.

commit 358b3803cdedad607cf649221d0b7e3ce66b45f2
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Tue Apr 25 17:14:40 2017 -0400

    Shake dumb compile-time bugs out of new logout code.
    
    What I get for writing code while build and test environment is tied
    up with a multi-day run testing something else.
---
 hal_internal.h |  2 +-
 ks_volatile.c  |  6 +++---
 rpc_misc.c     | 14 ++++++++++----
 rpc_pkey.c     | 19 +++++++++++++++++--
 4 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/hal_internal.h b/hal_internal.h
index f6c31fe..13c79e9 100644
--- a/hal_internal.h
+++ b/hal_internal.h
@@ -696,7 +696,7 @@ static inline hal_error_t hal_ks_logout(hal_ks_t *ks,
   if (ks == NULL)
     return HAL_ERROR_BAD_ARGUMENTS;
 
-  if (ks->logout == NULL || client.handle == HAL_HANDLE_NONE)
+  if (ks->driver->logout == NULL || client.handle == HAL_HANDLE_NONE)
     return HAL_OK;
 
   return ks->driver->logout(ks, client);
diff --git a/ks_volatile.c b/ks_volatile.c
index 29c3576..6a17e45 100644
--- a/ks_volatile.c
+++ b/ks_volatile.c
@@ -614,10 +614,10 @@ static hal_error_t ks_get_attributes(hal_ks_t *ks,
   return err;
 }
 
-static void ks_logout(hal_ks_t *ks,
-                      hal_client_handle_t client)
+static hal_error_t ks_logout(hal_ks_t *ks,
+                             hal_client_handle_t client)
 {
-  if (ks == NULL || client.handle = HAL_HANDLE_NONE)
+  if (ks == NULL || client.handle == HAL_HANDLE_NONE)
     return HAL_ERROR_BAD_ARGUMENTS;
 
   ks_t *ksv = ks_to_ksv(ks);
diff --git a/rpc_misc.c b/rpc_misc.c
index 4db6ed3..e9ff4c6 100644
--- a/rpc_misc.c
+++ b/rpc_misc.c
@@ -110,7 +110,8 @@ static inline client_slot_t *alloc_slot(const hal_client_handle_t client,
 #if HAL_STATIC_CLIENT_STATE_BLOCKS > 0
 
   for (int i = 0; slot == NULL && i < sizeof(client_handle)/sizeof(*client_handle); i++)
-    if (client_handle[i].logged_in != HAL_USER_NONE && client_handle[i].handle.handle == handle.handle)
+    if (client_handle[i].logged_in != HAL_USER_NONE &&
+        client_handle[i].handle.handle == client.handle)
       slot = &client_handle[i];
 
   for (int i = 0; slot == NULL && i < sizeof(client_handle)/sizeof(*client_handle); i++)
@@ -128,18 +129,23 @@ static inline client_slot_t *alloc_slot(const hal_client_handle_t client,
   return slot;
 }
 
-static inline void clear_slot(client_slot_t *slot)
+static inline hal_error_t clear_slot(client_slot_t *slot)
 {
   if (slot == NULL)
-    return;
+    return HAL_OK;
+
+  hal_error_t err;
 
-  hal_pkey_logout(slot->handle);
+  if ((err = hal_pkey_logout(slot->handle)) != HAL_OK)
+    return err;
 
   hal_critical_section_start();
 
   memset(slot, 0, sizeof(*slot));
 
   hal_critical_section_end();
+
+  return HAL_OK;
 }
 
 static inline client_slot_t *find_handle(const hal_client_handle_t handle)
diff --git a/rpc_pkey.c b/rpc_pkey.c
index 165419e..5af6c0e 100644
--- a/rpc_pkey.c
+++ b/rpc_pkey.c
@@ -138,9 +138,24 @@ hal_error_t hal_pkey_logout(const hal_client_handle_t client)
     return HAL_OK;
 
   hal_error_t err;
+  hal_ks_t *ks;
 
-  if ((err = hal_ks_logout(hal_ks_volatile_driver, client)) != HAL_OK ||
-      (err = hal_ks_logout(hal_ks_flash_driver,    client)) != HAL_OK)
+  if ((err = hal_ks_open(hal_ks_volatile_driver, &ks)) != HAL_OK)
+    return err;
+  if ((err = hal_ks_logout(ks, client)) == HAL_OK)
+    err = hal_ks_close(ks);
+  else
+    (void) hal_ks_close(ks);
+  if (err != HAL_OK)
+    return err;
+
+  if ((err = hal_ks_open(hal_ks_token_driver, &ks)) != HAL_OK)
+    return err;
+  if ((err = hal_ks_logout(ks, client)) == HAL_OK)
+    err = hal_ks_close(ks);
+  else
+    (void) hal_ks_close(ks);
+  if (err != HAL_OK)
     return err;
 
   hal_critical_section_start();



More information about the Commits mailing list