libopensc: check data returned by 'read-public-key'

fix error message
This commit is contained in:
Viktor Tarasov 2012-11-11 21:47:10 +01:00
parent da5934a6ff
commit f7771c9b08
3 changed files with 6 additions and 2 deletions

View File

@ -90,8 +90,8 @@ const char *sc_strerror(int error)
"Required ASN.1 object not found", "Required ASN.1 object not found",
"Premature end of ASN.1 stream", "Premature end of ASN.1 stream",
"Out of memory", "Out of memory",
"Too many objects",
"Object not valid", "Object not valid",
"Object not found",
"Requested object not found", "Requested object not found",
"Not supported", "Not supported",
"Passphrase required", "Passphrase required",

View File

@ -685,6 +685,9 @@ sc_pkcs15_read_pubkey(struct sc_pkcs15_card *p15card, const struct sc_pkcs15_obj
LOG_TEST_RET(ctx, SC_ERROR_NOT_IMPLEMENTED, "No way to get public key"); LOG_TEST_RET(ctx, SC_ERROR_NOT_IMPLEMENTED, "No way to get public key");
} }
if (!data || !len)
LOG_FUNC_RETURN(ctx, SC_ERROR_OBJECT_NOT_VALID);
pubkey = calloc(1, sizeof(struct sc_pkcs15_pubkey)); pubkey = calloc(1, sizeof(struct sc_pkcs15_pubkey));
if (pubkey == NULL) { if (pubkey == NULL) {
free(data); free(data);

View File

@ -788,7 +788,8 @@ static int read_ssh_key(void)
r = authenticate(obj); r = authenticate(obj);
if (r >= 0) if (r >= 0)
r = sc_pkcs15_read_pubkey(p15card, obj, &pubkey); r = sc_pkcs15_read_pubkey(p15card, obj, &pubkey);
} else if (r == SC_ERROR_OBJECT_NOT_FOUND) { }
else if (r == SC_ERROR_OBJECT_NOT_FOUND) {
/* No pubkey - try if there's a certificate */ /* No pubkey - try if there's a certificate */
r = sc_pkcs15_find_cert_by_id(p15card, &id, &obj); r = sc_pkcs15_find_cert_by_id(p15card, &id, &obj);
if (r >= 0) { if (r >= 0) {