From 333e51280497722c7f466b1c7905a3fd76290d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vesa=20J=C3=A4=C3=A4skel=C3=A4inen?= Date: Fri, 22 Dec 2023 09:35:28 +0200 Subject: [PATCH] libckteec: Fix CK_ULONG conversions in C_GetTokenInfo() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running in 64 bit CPU things like ulMaxSessionCount would get value of 4294967295 instead of ~0. Adjust all other CK_ULONG fields supporting CK_UNAVAILABLE_INFORMATION. Signed-off-by: Vesa Jääskeläinen Reviewed-by: Etienne Carriere --- libckteec/src/pkcs11_token.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libckteec/src/pkcs11_token.c b/libckteec/src/pkcs11_token.c index 0b262f74..00bb6ca3 100644 --- a/libckteec/src/pkcs11_token.c +++ b/libckteec/src/pkcs11_token.c @@ -250,16 +250,20 @@ CK_RV ck_token_get_info(CK_SLOT_ID slot, CK_TOKEN_INFO_PTR info) sizeof(info->serialNumber)); info->flags = ta_info->flags; - info->ulMaxSessionCount = ta_info->max_session_count; - info->ulSessionCount = ta_info->session_count; - info->ulMaxRwSessionCount = ta_info->max_rw_session_count; - info->ulRwSessionCount = ta_info->rw_session_count; + info->ulMaxSessionCount = maybe_unavail(ta_info->max_session_count); + info->ulSessionCount = maybe_unavail(ta_info->session_count); + info->ulMaxRwSessionCount = + maybe_unavail(ta_info->max_rw_session_count); + info->ulRwSessionCount = maybe_unavail(ta_info->rw_session_count); info->ulMaxPinLen = ta_info->max_pin_len; info->ulMinPinLen = ta_info->min_pin_len; - info->ulTotalPublicMemory = ta_info->total_public_memory; - info->ulFreePublicMemory = ta_info->free_public_memory; - info->ulTotalPrivateMemory = ta_info->total_private_memory; - info->ulFreePrivateMemory = ta_info->free_private_memory; + info->ulTotalPublicMemory = + maybe_unavail(ta_info->total_public_memory); + info->ulFreePublicMemory = maybe_unavail(ta_info->free_public_memory); + info->ulTotalPrivateMemory = + maybe_unavail(ta_info->total_private_memory); + info->ulFreePrivateMemory = + maybe_unavail(ta_info->free_private_memory); COMPILE_TIME_ASSERT(sizeof(info->hardwareVersion) == sizeof(ta_info->hardware_version));