Coverity warnings
card-piv.c make sure the string is null terminated before passing it to hex_to_bin routine, which expects it pkcs15-cac.c free cn_name on failure pkcs11-tool.c make sure the string is null terminated before passing it to parse_certificate(), which expects it
This commit is contained in:
parent
83b188c950
commit
b9e33a3c64
|
@ -1481,7 +1481,7 @@ static int piv_get_key(sc_card_t *card, unsigned int alg_id, u8 **key, size_t *l
|
|||
FILE *f = NULL;
|
||||
char * keyfilename = NULL;
|
||||
size_t expected_keylen;
|
||||
size_t keylen;
|
||||
size_t keylen, readlen;
|
||||
u8 * keybuf = NULL;
|
||||
u8 * tkey = NULL;
|
||||
|
||||
|
@ -1530,11 +1530,12 @@ static int piv_get_key(sc_card_t *card, unsigned int alg_id, u8 **key, size_t *l
|
|||
}
|
||||
keybuf[fsize] = 0x00; /* in case it is text need null */
|
||||
|
||||
if (fread(keybuf, 1, fsize, f) != fsize) {
|
||||
if ((readlen = fread(keybuf, 1, fsize, f)) != fsize) {
|
||||
sc_log(card->ctx, " Unable to read key\n");
|
||||
r = SC_ERROR_WRONG_LENGTH;
|
||||
goto err;
|
||||
}
|
||||
keybuf[readlen] = '\0';
|
||||
|
||||
tkey = malloc(expected_keylen);
|
||||
if (!tkey) {
|
||||
|
|
|
@ -388,6 +388,7 @@ static int sc_pkcs15emu_cac_init(sc_pkcs15_card_t *p15card)
|
|||
if (r == SC_SUCCESS) {
|
||||
token_name = malloc (cn_len+1);
|
||||
if (!token_name) {
|
||||
free(cn_name);
|
||||
r = SC_ERROR_OUT_OF_MEMORY;
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
@ -2838,9 +2838,10 @@ static int write_object(CK_SESSION_HANDLE session)
|
|||
if (!(f = fopen(opt_attr_from_file, "rb")))
|
||||
util_fatal("Couldn't open file \"%s\"", opt_attr_from_file);
|
||||
certdata_len = fread(certdata, 1, sizeof(certdata), f);
|
||||
fclose(f);
|
||||
if (certdata_len < 0)
|
||||
util_fatal("Couldn't read from file \"%s\"", opt_attr_from_file);
|
||||
fclose(f);
|
||||
certdata[certdata_len] = '\0';
|
||||
need_to_parse_certdata = 1;
|
||||
}
|
||||
if (opt_object_class == CKO_CERTIFICATE) {
|
||||
|
|
Loading…
Reference in New Issue