Index: cackey.c ================================================================== --- cackey.c +++ cackey.c @@ -1372,12 +1372,14 @@ ssize_t tlen, vlen; ssize_t read_ret; size_t offset_t = 0, offset_v = 0; unsigned char tag; size_t length; +#ifdef HAVE_LIBZ uLongf tmpbuflen; int uncompress_ret; +#endif CACKEY_DEBUG_PRINTF("Called."); read_ret = cackey_read_buffer(slot, tlen_buf, sizeof(tlen_buf), 1, offset_t); if (read_ret != sizeof(tlen_buf)) { @@ -1480,11 +1482,10 @@ tmpbuflen = length * 2; tmpbuf = malloc(tmpbuflen); #ifdef HAVE_LIBZ - CACKEY_DEBUG_PRINTBUF("Decompressing:", vval, length); uncompress_ret = uncompress(tmpbuf, &tmpbuflen, vval, length); if (uncompress_ret != Z_OK) { CACKEY_DEBUG_PRINTF("Failed to decompress, uncompress() returned %i -- resorting to direct copy", uncompress_ret); tmpbuflen = length; @@ -2018,14 +2019,27 @@ CACKEY_DEBUG_PRINTF("Requesting attribute CKA_LABEL (0x%08lx) ...", (unsigned long) curr_attr_type); /* Determine name */ if (certificate_len >= 0) { x509_read_ret = x509_to_subject(certificate, certificate_len, &pValue); - if (x509_read_ret < 0) { - pValue = NULL; + if (x509_read_ret > 0) { + x509_read_ret = x509_dn_to_string(pValue, x509_read_ret, (char *) ucTmpBuf, sizeof(ucTmpBuf), "CN"); + if (x509_read_ret <= 0) { + x509_read_ret = x509_dn_to_string(pValue, x509_read_ret, (char *) ucTmpBuf, sizeof(ucTmpBuf), NULL); + + if (x509_read_ret <= 0) { + pValue = NULL; + } else { + pValue = ucTmpBuf; + ulValueLen = x509_read_ret; + } + } else { + pValue = ucTmpBuf; + ulValueLen = x509_read_ret; + } } else { - ulValueLen = x509_read_ret; + pValue = NULL; } } CACKEY_DEBUG_PRINTF(" ... returning (%p/%lu)", pValue, (unsigned long) ulValueLen);