From a54521bac3500cbc25f02bf412d7de49694bfd12 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Fri, 27 Dec 2024 14:33:31 +0100 Subject: [PATCH] Clear session opening errors on successful re-opening --- src/session.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/session.c b/src/session.c index 69c3a1f3..9c717df4 100644 --- a/src/session.c +++ b/src/session.c @@ -807,6 +807,7 @@ static CK_RV slot_login(P11PROV_SLOT *slot, P11PROV_URI *uri, } /* we acquired the session, check that it is ok */ + p11prov_set_error_mark(pool->provctx); ret = session_check(session, session->flags); if (ret != CKR_OK) { num_open_sessions--; @@ -816,9 +817,13 @@ static CK_RV slot_login(P11PROV_SLOT *slot, P11PROV_URI *uri, ret = token_session_open(session, flags); if (ret == CKR_OK) { num_open_sessions++; + p11prov_pop_error_to_mark(pool->provctx); } else { + p11prov_clear_last_error_mark(pool->provctx); goto done; } + } else { + p11prov_clear_last_error_mark(pool->provctx); } if (is_login_state(session->state)) { @@ -1008,6 +1013,7 @@ CK_RV p11prov_get_session(P11PROV_CTX *provctx, CK_SLOT_ID *slotid, ret = fetch_session(pool, flags, false, &session); if (ret == CKR_OK) { + p11prov_set_error_mark(pool->provctx); ret = session_check(session, flags); if (ret != CKR_OK) { num_open_sessions--; @@ -1017,8 +1023,11 @@ CK_RV p11prov_get_session(P11PROV_CTX *provctx, CK_SLOT_ID *slotid, ret = token_session_open(session, flags); if (ret == CKR_OK) { num_open_sessions++; + p11prov_pop_error_to_mark(pool->provctx); + goto done; } } + p11prov_clear_last_error_mark(pool->provctx); } done: