pkcs11: truncate oversized labels with '...'

This commit is contained in:
Frank Morgner 2019-03-08 22:02:30 +01:00
parent 1e6d3df201
commit 0079d836f3
1 changed files with 15 additions and 5 deletions

View File

@ -43,16 +43,26 @@ static struct sc_to_cryptoki_error_conversion sc_to_cryptoki_error_map[] = {
void strcpy_bp(u8 * dst, const char *src, size_t dstsize)
{
size_t c;
if (!dst || !src || !dstsize)
if (!dst || !dstsize)
return;
memset((char *)dst, ' ', dstsize);
c = strlen(src) > dstsize ? dstsize : strlen(src);
if (src) {
size_t src_len = strlen(src);
memcpy((char *)dst, src, c);
if (src_len > dstsize) {
/* string will be truncated */
memcpy((char *)dst, src, dstsize);
if (dstsize > 3) {
/* show truncation with '...' */
/* FIXME avoid breaking an UTF-8 character on multiple bytes */
memset((char *)dst + dstsize - 3, '.', 3);
}
} else {
memcpy((char *)dst, src, src_len);
}
}
}