If we fail to create a session, invalidade the session
  handler and check that when closing sessions.

  Trying to C_CloseSession() on an invalid handle may
  segfault the caller.

Signed-off-by: Klaus Heinrich Kiwi <[email protected]>
---
 testcases/include/regress.h |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/testcases/include/regress.h b/testcases/include/regress.h
index ec22e77..d8b04f7 100755
--- a/testcases/include/regress.h
+++ b/testcases/include/regress.h
@@ -179,6 +179,7 @@ int get_user_pin(CK_BYTE_PTR);
                 if (rc != CKR_OK) {                                     \
                         testcase_error("C_OpenSession() rc = %s",       \
                                 p11_get_ckr(rc));                       \
+                        session = CK_INVALID_HANDLE;                    \
                         goto testcase_cleanup;                          \
                 }                                                       \
         } while (0)
@@ -191,17 +192,20 @@ int get_user_pin(CK_BYTE_PTR);
                 if (rc != CKR_OK) {                                     \
                         testcase_error("C_OpenSession() rc = %s",       \
                                 p11_get_ckr(rc));                       \
+                        session = CK_INVALID_HANDLE;                    \
                         goto testcase_cleanup;                          \
                 }                                                       \
         } while (0)
 
-#define testcase_close_session()                                        \
-        do {                                                            \
-                rc = funcs->C_CloseSession(session);                    \
-                if (rc != CKR_OK) {                                     \
-                        testcase_error("C_CloseSession() rc = %s",      \
-                                p11_get_ckr(rc));                       \
-                }                                                       \
+#define testcase_close_session()                                               
 \
+        do {                                                                   
 \
+                if (session != CK_INVALID_HANDLE) {                            
 \
+                        rc = funcs->C_CloseSession(session);                   
 \
+                        if (rc != CKR_OK) {                                    
 \
+                                testcase_error("C_CloseSession() rc = %s",     
 \
+                                                p11_get_ckr(rc));              
 \
+                        }                                                      
 \
+                }                                                              
 \
         } while (0)
 
 #define testcase_closeall_session()                                     \
-- 
1.7.2.3


------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Opencryptoki-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opencryptoki-tech

Reply via email to