sc_bin_to_hex returns a Nul terminated string

This commit is contained in:
Frank Morgner 2019-03-03 21:26:20 +01:00
parent eb8f28db20
commit 9fa1722f73
4 changed files with 11 additions and 11 deletions

View File

@ -251,7 +251,7 @@ sc_pkcs15emu_din_66291_init(sc_pkcs15_card_t *p15card)
if (!p15card->tokeninfo->serial_number
&& SC_SUCCESS == sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &serial)) {
char serial_hex[SC_MAX_SERIALNR*2+2];
sc_bin_to_hex(serial.value, serial.len , serial_hex, sizeof serial_hex - 1, 0);
sc_bin_to_hex(serial.value, serial.len , serial_hex, sizeof serial_hex, 0);
p15card->tokeninfo->serial_number = strdup(serial_hex);
}

View File

@ -224,13 +224,13 @@ static int sc_pkcs15emu_gemsafeGPK_init(sc_pkcs15_card_t *p15card)
p15card->tokeninfo->label = strdup("GemSAFE");
p15card->tokeninfo->manufacturer_id = strdup(MANU_ID);
/* get serial number */
r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
if (r != SC_SUCCESS)
return SC_ERROR_INTERNAL;
r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
if (r != SC_SUCCESS)
return SC_ERROR_INTERNAL;
p15card->tokeninfo->serial_number = strdup(buf);
r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, &serial);
if (r != SC_SUCCESS)
return SC_ERROR_INTERNAL;
r = sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
if (r != SC_SUCCESS)
return SC_ERROR_INTERNAL;
p15card->tokeninfo->serial_number = strdup(buf);
/* test if we have a gemsafe app df */
memset(&path, 0, sizeof(path));

View File

@ -182,7 +182,7 @@ sc_pkcs15emu_openpgp_init(sc_pkcs15_card_t *p15card)
unsigned short manuf_id = bebytes2ushort(card->serialnr.value);
int j;
sc_bin_to_hex(card->serialnr.value, card->serialnr.len, string, sizeof(string)-1, 0);
sc_bin_to_hex(card->serialnr.value, card->serialnr.len, string, sizeof(string), 0);
set_string(&p15card->tokeninfo->serial_number, string);
for (j = 0; manuf_map[j].name != NULL; j++) {

View File

@ -511,9 +511,9 @@ int sc_pkcs15emu_tcos_init_ex(
sc_log(ctx, "unable to get ICCSN\n");
return SC_ERROR_WRONG_CARD;
}
sc_bin_to_hex(serialnr.value, serialnr.len , serial, sizeof(serial), 0);
sc_bin_to_hex(serialnr.value, serialnr.len , serial, sizeof(serial), 0);
serial[19] = '\0';
p15card->tokeninfo->serial_number = strdup(serial);
p15card->tokeninfo->serial_number = strdup(serial);
if(!detect_netkey(p15card)) return SC_SUCCESS;
if(!detect_idkey(p15card)) return SC_SUCCESS;