- Don't crash if card->serial_number is NULL

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1749 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
okir 2004-02-02 10:24:31 +00:00
parent 20e2b1b94b
commit 393de85ac1
1 changed files with 16 additions and 8 deletions

View File

@ -164,16 +164,24 @@ static CK_RV pkcs15_unbind(struct sc_pkcs11_card *p11card)
static void pkcs15_init_token_info(struct sc_pkcs15_card *card, CK_TOKEN_INFO_PTR pToken)
{
int sn_start = strlen(card->serial_number) - 16;
strcpy_bp(pToken->manufacturerID, card->manufacturer_id, 32);
strcpy_bp(pToken->model, "PKCS #15 SCard", 16);
/* Take the last 16 chars of the serial number (if the are more then 16).
_Assuming_ that the serial number is a Big Endian counter, this will
assure that the serial within each type of card will be unique in pkcs11
(at least for the first 16^16 cards :-) */
if (sn_start < 0)
sn_start = 0;
strcpy_bp(pToken->serialNumber, card->serial_number + sn_start, 16);
/* Take the last 16 chars of the serial number (if the are more
* than 16).
* _Assuming_ that the serial number is a Big Endian counter, this
* will assure that the serial within each type of card will be
* unique in pkcs11 (at least for the first 8^16 cards :-) */
if (card->serial_number != NULL) {
int sn_start = strlen(card->serial_number) - 16;
if (sn_start < 0)
sn_start = 0;
strcpy_bp(pToken->serialNumber,
card->serial_number + sn_start,
16);
}
pToken->ulMaxSessionCount = CK_EFFECTIVELY_INFINITE;
pToken->ulSessionCount = 0; /* FIXME */
pToken->ulMaxRwSessionCount = CK_EFFECTIVELY_INFINITE;