fixed dereference before null check
silence warnings reported by coverity-scan
This commit is contained in:
parent
b13bb3cbf5
commit
7a34c204c1
|
@ -234,7 +234,7 @@ main(int argc, char * argv[])
|
||||||
case 'o': /* -output=FILE */
|
case 'o': /* -output=FILE */
|
||||||
outfilename = optarg;
|
outfilename = optarg;
|
||||||
/* we allow "-" as a synonym for stdout here */
|
/* we allow "-" as a synonym for stdout here */
|
||||||
if (! strcmp(optarg, "-"))
|
if (optarg && !strcmp(optarg, "-"))
|
||||||
{
|
{
|
||||||
outfilename = 0;
|
outfilename = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -650,7 +650,7 @@ authentic_reduce_path(struct sc_card *card, struct sc_path *path)
|
||||||
|
|
||||||
LOG_FUNC_CALLED(ctx);
|
LOG_FUNC_CALLED(ctx);
|
||||||
|
|
||||||
if (path->len <= 2 || path->type == SC_PATH_TYPE_DF_NAME || !path)
|
if (!path || path->len <= 2 || path->type == SC_PATH_TYPE_DF_NAME)
|
||||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||||
|
|
||||||
if (!card->cache.valid || !card->cache.current_df)
|
if (!card->cache.valid || !card->cache.current_df)
|
||||||
|
|
|
@ -2565,6 +2565,7 @@ iasecc_sdo_create(struct sc_card *card, struct iasecc_sdo *sdo)
|
||||||
rv = iasecc_sdo_put_data(card, &update);
|
rv = iasecc_sdo_put_data(card, &update);
|
||||||
LOG_TEST_RET(ctx, rv, "failed to update 'Compulsory usage' data");
|
LOG_TEST_RET(ctx, rv, "failed to update 'Compulsory usage' data");
|
||||||
|
|
||||||
|
if (field)
|
||||||
field->on_card = 1;
|
field->on_card = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3252,14 +3253,19 @@ static int
|
||||||
iasecc_compute_signature(struct sc_card *card,
|
iasecc_compute_signature(struct sc_card *card,
|
||||||
const unsigned char *in, size_t in_len, unsigned char *out, size_t out_len)
|
const unsigned char *in, size_t in_len, unsigned char *out, size_t out_len)
|
||||||
{
|
{
|
||||||
struct sc_context *ctx = card->ctx;
|
struct sc_context *ctx;
|
||||||
struct iasecc_private_data *prv = (struct iasecc_private_data *) card->drv_data;
|
struct iasecc_private_data *prv;
|
||||||
struct sc_security_env *env = &prv->security_env;
|
struct sc_security_env *env;
|
||||||
|
|
||||||
|
if (!card || !in || !out)
|
||||||
|
return SC_ERROR_INVALID_ARGUMENTS;
|
||||||
|
|
||||||
|
ctx = card->ctx;
|
||||||
|
prv = (struct iasecc_private_data *) card->drv_data;
|
||||||
|
env = &prv->security_env;
|
||||||
|
|
||||||
LOG_FUNC_CALLED(ctx);
|
LOG_FUNC_CALLED(ctx);
|
||||||
sc_log(ctx, "inlen %i, outlen %i", in_len, out_len);
|
sc_log(ctx, "inlen %i, outlen %i", in_len, out_len);
|
||||||
if (!card || !in || !out)
|
|
||||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid compute signature arguments");
|
|
||||||
|
|
||||||
if (env->operation == SC_SEC_OPERATION_SIGN)
|
if (env->operation == SC_SEC_OPERATION_SIGN)
|
||||||
return iasecc_compute_signature_dst(card, in, in_len, out, out_len);
|
return iasecc_compute_signature_dst(card, in, in_len, out, out_len);
|
||||||
|
|
|
@ -1108,16 +1108,17 @@ auth_compute_signature(struct sc_card *card, const unsigned char *in, size_t ile
|
||||||
unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
|
unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
|
||||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "inlen %i, outlen %i\n", ilen, olen);
|
|
||||||
if (!card || !in || !out) {
|
if (!card || !in || !out) {
|
||||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS);
|
return SC_ERROR_INVALID_ARGUMENTS;
|
||||||
}
|
}
|
||||||
else if (ilen > 96) {
|
else if (ilen > 96) {
|
||||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Illegal input length %d\n", ilen);
|
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Illegal input length %d\n", ilen);
|
||||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "Illegal input length");
|
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "Illegal input length");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
||||||
|
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "inlen %i, outlen %i\n", ilen, olen);
|
||||||
|
|
||||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0x9A);
|
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0x9A);
|
||||||
apdu.datalen = ilen;
|
apdu.datalen = ilen;
|
||||||
apdu.data = in;
|
apdu.data = in;
|
||||||
|
|
|
@ -1109,6 +1109,15 @@ static int westcos_sign_decipher(int mode, sc_card_t *card,
|
||||||
return SC_ERROR_INVALID_ARGUMENTS;
|
return SC_ERROR_INVALID_ARGUMENTS;
|
||||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
|
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
|
||||||
"westcos_sign_decipher outlen=%d\n", outlen);
|
"westcos_sign_decipher outlen=%d\n", outlen);
|
||||||
|
|
||||||
|
#ifndef ENABLE_OPENSSL
|
||||||
|
r = SC_ERROR_NOT_SUPPORTED;
|
||||||
|
#else
|
||||||
|
if (keyfile == NULL || mem == NULL || card->drv_data == NULL) {
|
||||||
|
r = SC_ERROR_OUT_OF_MEMORY;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
priv_data = (priv_data_t *) card->drv_data;
|
priv_data = (priv_data_t *) card->drv_data;
|
||||||
|
|
||||||
if(priv_data->flags & RSA_CRYPTO_COMPONENT)
|
if(priv_data->flags & RSA_CRYPTO_COMPONENT)
|
||||||
|
@ -1134,14 +1143,6 @@ static int westcos_sign_decipher(int mode, sc_card_t *card,
|
||||||
r = apdu.resplen;
|
r = apdu.resplen;
|
||||||
goto out2;
|
goto out2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ENABLE_OPENSSL
|
|
||||||
r = SC_ERROR_NOT_SUPPORTED;
|
|
||||||
#else
|
|
||||||
if (keyfile == NULL || mem == NULL || priv_data == NULL) {
|
|
||||||
r = SC_ERROR_OUT_OF_MEMORY;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
if ((priv_data->env.flags) & SC_ALGORITHM_RSA_PAD_PKCS1)
|
if ((priv_data->env.flags) & SC_ALGORITHM_RSA_PAD_PKCS1)
|
||||||
pad = RSA_PKCS1_PADDING;
|
pad = RSA_PKCS1_PADDING;
|
||||||
|
|
||||||
|
|
|
@ -403,10 +403,11 @@ int sc_create_file(sc_card_t *card, sc_file_t *file)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
char pbuf[SC_MAX_PATH_STRING_SIZE];
|
char pbuf[SC_MAX_PATH_STRING_SIZE];
|
||||||
const sc_path_t *in_path = &file->path;
|
const sc_path_t *in_path;
|
||||||
|
|
||||||
assert(card != NULL);
|
assert(card != NULL && file != NULL);
|
||||||
|
|
||||||
|
in_path = &file->path;
|
||||||
r = sc_path_print(pbuf, sizeof(pbuf), in_path);
|
r = sc_path_print(pbuf, sizeof(pbuf), in_path);
|
||||||
if (r != SC_SUCCESS)
|
if (r != SC_SUCCESS)
|
||||||
pbuf[0] = '\0';
|
pbuf[0] = '\0';
|
||||||
|
@ -864,14 +865,16 @@ sc_algorithm_info_t * sc_card_find_gostr3410_alg(sc_card_t *card,
|
||||||
|
|
||||||
static int match_atr_table(sc_context_t *ctx, struct sc_atr_table *table, struct sc_atr *atr)
|
static int match_atr_table(sc_context_t *ctx, struct sc_atr_table *table, struct sc_atr *atr)
|
||||||
{
|
{
|
||||||
u8 *card_atr_bin = atr->value;
|
u8 *card_atr_bin;
|
||||||
size_t card_atr_bin_len = atr->len;
|
size_t card_atr_bin_len;
|
||||||
char card_atr_hex[3 * SC_MAX_ATR_SIZE];
|
char card_atr_hex[3 * SC_MAX_ATR_SIZE];
|
||||||
size_t card_atr_hex_len;
|
size_t card_atr_hex_len;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
|
|
||||||
if (ctx == NULL || table == NULL || atr == NULL)
|
if (ctx == NULL || table == NULL || atr == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
card_atr_bin = atr->value;
|
||||||
|
card_atr_bin_len = atr->len;
|
||||||
sc_bin_to_hex(card_atr_bin, card_atr_bin_len, card_atr_hex, sizeof(card_atr_hex), ':');
|
sc_bin_to_hex(card_atr_bin, card_atr_bin_len, card_atr_hex, sizeof(card_atr_hex), ':');
|
||||||
card_atr_hex_len = strlen(card_atr_hex);
|
card_atr_hex_len = strlen(card_atr_hex);
|
||||||
|
|
||||||
|
|
|
@ -1434,10 +1434,6 @@ int cwa_encode_apdu(sc_card_t * card,
|
||||||
u8 *msgbuf = NULL; /* to encrypt apdu data */
|
u8 *msgbuf = NULL; /* to encrypt apdu data */
|
||||||
u8 *cryptbuf = NULL;
|
u8 *cryptbuf = NULL;
|
||||||
|
|
||||||
/* reserve extra bytes for padding and tlv header */
|
|
||||||
msgbuf = calloc(12 + from->lc, sizeof(u8)); /* to encrypt apdu data */
|
|
||||||
cryptbuf = calloc(12 + from->lc, sizeof(u8));
|
|
||||||
|
|
||||||
/* mandatory check */
|
/* mandatory check */
|
||||||
if (!card || !card->ctx || !provider)
|
if (!card || !card->ctx || !provider)
|
||||||
return SC_ERROR_INVALID_ARGUMENTS;
|
return SC_ERROR_INVALID_ARGUMENTS;
|
||||||
|
@ -1450,6 +1446,10 @@ int cwa_encode_apdu(sc_card_t * card,
|
||||||
LOG_FUNC_RETURN(ctx, SC_ERROR_SM_NOT_INITIALIZED);
|
LOG_FUNC_RETURN(ctx, SC_ERROR_SM_NOT_INITIALIZED);
|
||||||
if (sm_session->state != CWA_SM_ACTIVE)
|
if (sm_session->state != CWA_SM_ACTIVE)
|
||||||
LOG_FUNC_RETURN(ctx, SC_ERROR_SM_INVALID_LEVEL);
|
LOG_FUNC_RETURN(ctx, SC_ERROR_SM_INVALID_LEVEL);
|
||||||
|
|
||||||
|
/* reserve extra bytes for padding and tlv header */
|
||||||
|
msgbuf = calloc(12 + from->lc, sizeof(u8)); /* to encrypt apdu data */
|
||||||
|
cryptbuf = calloc(12 + from->lc, sizeof(u8));
|
||||||
if (!msgbuf || !cryptbuf)
|
if (!msgbuf || !cryptbuf)
|
||||||
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
|
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
|
||||||
|
|
||||||
|
|
|
@ -274,6 +274,7 @@ void sc_format_path(const char *str, sc_path_t *path)
|
||||||
{
|
{
|
||||||
int type = SC_PATH_TYPE_PATH;
|
int type = SC_PATH_TYPE_PATH;
|
||||||
|
|
||||||
|
if (path) {
|
||||||
memset(path, 0, sizeof(*path));
|
memset(path, 0, sizeof(*path));
|
||||||
if (*str == 'i' || *str == 'I') {
|
if (*str == 'i' || *str == 'I') {
|
||||||
type = SC_PATH_TYPE_FILE_ID;
|
type = SC_PATH_TYPE_FILE_ID;
|
||||||
|
@ -284,7 +285,7 @@ void sc_format_path(const char *str, sc_path_t *path)
|
||||||
path->type = type;
|
path->type = type;
|
||||||
}
|
}
|
||||||
path->count = -1;
|
path->count = -1;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int sc_append_path(sc_path_t *dest, const sc_path_t *src)
|
int sc_append_path(sc_path_t *dest, const sc_path_t *src)
|
||||||
|
|
|
@ -3446,10 +3446,12 @@ pkcs15_prkey_get_attribute(struct sc_pkcs11_session *session,
|
||||||
check_attribute_buffer(attr, sizeof(CK_ULONG));
|
check_attribute_buffer(attr, sizeof(CK_ULONG));
|
||||||
switch (prkey->prv_p15obj->type) {
|
switch (prkey->prv_p15obj->type) {
|
||||||
case SC_PKCS15_TYPE_PRKEY_EC:
|
case SC_PKCS15_TYPE_PRKEY_EC:
|
||||||
if (key && key->u.ec.params.field_length > 0)
|
if (key) {
|
||||||
|
if (key->u.ec.params.field_length > 0)
|
||||||
*(CK_ULONG *) attr->pValue = key->u.ec.params.field_length;
|
*(CK_ULONG *) attr->pValue = key->u.ec.params.field_length;
|
||||||
else
|
else
|
||||||
*(CK_ULONG *) attr->pValue = (key->u.ec.ecpointQ.len - 1) / 2 *8;
|
*(CK_ULONG *) attr->pValue = (key->u.ec.ecpointQ.len - 1) / 2 *8;
|
||||||
|
}
|
||||||
return CKR_OK;
|
return CKR_OK;
|
||||||
default:
|
default:
|
||||||
*(CK_ULONG *) attr->pValue = prkey->prv_info->modulus_length;
|
*(CK_ULONG *) attr->pValue = prkey->prv_info->modulus_length;
|
||||||
|
|
|
@ -688,7 +688,7 @@ out:
|
||||||
sc_wait_for_event(context, 0, NULL, NULL, -1, &reader_states);
|
sc_wait_for_event(context, 0, NULL, NULL, -1, &reader_states);
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_log(context, "C_WaitForSlotEvent() = %s, event in 0x%lx", lookup_enum (RV_T, rv), *pSlot);
|
sc_log(context, "C_WaitForSlotEvent() = %s", lookup_enum (RV_T, rv));
|
||||||
sc_pkcs11_unlock();
|
sc_pkcs11_unlock();
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,11 +292,10 @@ static int entersafe_create_pin(sc_profile_t *profile, sc_pkcs15_card_t *p15card
|
||||||
data.key_data.symmetric.key_len=16;
|
data.key_data.symmetric.key_len=16;
|
||||||
|
|
||||||
r = sc_card_ctl(card, SC_CARDCTL_ENTERSAFE_WRITE_KEY, &data);
|
r = sc_card_ctl(card, SC_CARDCTL_ENTERSAFE_WRITE_KEY, &data);
|
||||||
if (pin_obj) {
|
|
||||||
/* Cache new PIN value. */
|
/* Cache new PIN value. */
|
||||||
sc_pkcs15_pincache_add(p15card, pin_obj, pin, pin_len);
|
sc_pkcs15_pincache_add(p15card, pin_obj, pin, pin_len);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
{/*puk*/
|
{/*puk*/
|
||||||
sc_entersafe_wkey_data data;
|
sc_entersafe_wkey_data data;
|
||||||
|
|
|
@ -470,7 +470,6 @@ static int epass2003_pkcs15_store_key(struct sc_profile *profile,
|
||||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||||
"store key: cannot update private key");
|
"store key: cannot update private key");
|
||||||
|
|
||||||
if (file)
|
|
||||||
sc_file_free(file);
|
sc_file_free(file);
|
||||||
|
|
||||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
|
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
|
||||||
|
|
|
@ -458,7 +458,6 @@ gpk_create_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_pkcs15_objec
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (keyfile)
|
|
||||||
sc_file_free(keyfile);
|
sc_file_free(keyfile);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,6 @@ jcop_create_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_pkcs15_obje
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
r = sc_pkcs15init_create_file(profile, p15card, keyfile);
|
r = sc_pkcs15init_create_file(profile, p15card, keyfile);
|
||||||
|
|
||||||
if (keyfile)
|
|
||||||
sc_file_free(keyfile);
|
sc_file_free(keyfile);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1888,7 +1888,6 @@ sc_pkcs15init_store_data(struct sc_pkcs15_card *p15card, struct sc_profile *prof
|
||||||
|
|
||||||
*path = file->path;
|
*path = file->path;
|
||||||
|
|
||||||
if (file)
|
|
||||||
sc_file_free(file);
|
sc_file_free(file);
|
||||||
LOG_FUNC_RETURN(ctx, r);
|
LOG_FUNC_RETURN(ctx, r);
|
||||||
}
|
}
|
||||||
|
@ -2197,7 +2196,7 @@ sc_pkcs15init_select_intrinsic_id(struct sc_pkcs15_card *p15card, struct sc_prof
|
||||||
{
|
{
|
||||||
struct sc_context *ctx = p15card->card->ctx;
|
struct sc_context *ctx = p15card->card->ctx;
|
||||||
struct sc_pkcs15_pubkey *pubkey = NULL;
|
struct sc_pkcs15_pubkey *pubkey = NULL;
|
||||||
unsigned id_style = profile->id_style;
|
unsigned id_style;
|
||||||
struct sc_pkcs15_id id;
|
struct sc_pkcs15_id id;
|
||||||
unsigned char *id_data = NULL;
|
unsigned char *id_data = NULL;
|
||||||
size_t id_data_len = 0;
|
size_t id_data_len = 0;
|
||||||
|
@ -2207,15 +2206,17 @@ sc_pkcs15init_select_intrinsic_id(struct sc_pkcs15_card *p15card, struct sc_prof
|
||||||
#ifndef ENABLE_OPENSSL
|
#ifndef ENABLE_OPENSSL
|
||||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||||
#else
|
#else
|
||||||
if (!id_out)
|
if (!id_out || !profile)
|
||||||
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
|
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
|
||||||
|
|
||||||
|
id_style = profile->id_style;
|
||||||
|
|
||||||
/* ID already exists */
|
/* ID already exists */
|
||||||
if (id_out->len)
|
if (id_out->len)
|
||||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||||
|
|
||||||
/* Native ID style is not intrisic one */
|
/* Native ID style is not intrisic one */
|
||||||
if (profile->id_style == SC_PKCS15INIT_ID_STYLE_NATIVE)
|
if (id_style == SC_PKCS15INIT_ID_STYLE_NATIVE)
|
||||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||||
|
|
||||||
memset(&id, 0, sizeof(id));
|
memset(&id, 0, sizeof(id));
|
||||||
|
@ -2283,7 +2284,7 @@ sc_pkcs15init_select_intrinsic_id(struct sc_pkcs15_card *p15card, struct sc_prof
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sc_log(ctx, "Unsupported ID style: %i", profile->id_style);
|
sc_log(ctx, "Unsupported ID style: %i", id_style);
|
||||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Non supported ID style");
|
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Non supported ID style");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3238,7 +3239,6 @@ sc_pkcs15init_verify_secret(struct sc_profile *profile, struct sc_pkcs15_card *p
|
||||||
sc_log(ctx, "Symbolic PIN resolved to PIN(type:CHV,reference:%i)", type, reference);
|
sc_log(ctx, "Symbolic PIN resolved to PIN(type:CHV,reference:%i)", type, reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p15card) {
|
|
||||||
if (path && path->len) {
|
if (path && path->len) {
|
||||||
struct sc_path tmp_path = *path;
|
struct sc_path tmp_path = *path;
|
||||||
int iter;
|
int iter;
|
||||||
|
@ -3257,7 +3257,6 @@ sc_pkcs15init_verify_secret(struct sc_profile *profile, struct sc_pkcs15_card *p
|
||||||
memcpy(&auth_info, pin_obj->data, sizeof(auth_info));
|
memcpy(&auth_info, pin_obj->data, sizeof(auth_info));
|
||||||
sc_log(ctx, "found PIN object '%s'", pin_obj->label);
|
sc_log(ctx, "found PIN object '%s'", pin_obj->label);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (pin_obj) {
|
if (pin_obj) {
|
||||||
sc_log(ctx, "PIN object '%s'; pin_obj->content.len:%i", pin_obj->label, pin_obj->content.len);
|
sc_log(ctx, "PIN object '%s'; pin_obj->content.len:%i", pin_obj->label, pin_obj->content.len);
|
||||||
|
|
|
@ -189,7 +189,7 @@ myeid_init_card(sc_profile_t *profile,
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
myeid_create_dir(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file_t *df) {
|
myeid_create_dir(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file_t *df) {
|
||||||
struct sc_context *ctx = p15card->card->ctx;
|
struct sc_context *ctx;
|
||||||
struct sc_file *file = NULL;
|
struct sc_file *file = NULL;
|
||||||
int r = 0, ii;
|
int r = 0, ii;
|
||||||
static const char *create_dfs[] = {
|
static const char *create_dfs[] = {
|
||||||
|
@ -209,9 +209,10 @@ myeid_create_dir(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file_t *df
|
||||||
SC_PKCS15_DODF
|
SC_PKCS15_DODF
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!profile || !p15card || !df)
|
if (!profile || !p15card || !p15card->card || !df)
|
||||||
return SC_ERROR_INVALID_ARGUMENTS;
|
return SC_ERROR_INVALID_ARGUMENTS;
|
||||||
|
|
||||||
|
ctx = p15card->card->ctx;
|
||||||
LOG_FUNC_CALLED(ctx);
|
LOG_FUNC_CALLED(ctx);
|
||||||
sc_log(ctx, "id (%x)", df->id);
|
sc_log(ctx, "id (%x)", df->id);
|
||||||
|
|
||||||
|
|
|
@ -330,12 +330,10 @@ awp_create_container(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
||||||
|
|
||||||
rv = awp_create_container_record(p15card, profile, file, acc);
|
rv = awp_create_container_record(p15card, profile, file, acc);
|
||||||
|
|
||||||
if (clist)
|
|
||||||
sc_file_free(clist);
|
|
||||||
if (file)
|
|
||||||
sc_file_free(file);
|
|
||||||
if (list)
|
if (list)
|
||||||
free(list);
|
free(list);
|
||||||
|
sc_file_free(file);
|
||||||
|
sc_file_free(clist);
|
||||||
|
|
||||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
||||||
}
|
}
|
||||||
|
@ -1669,8 +1667,8 @@ awp_delete_from_container(struct sc_pkcs15_card *p15card,
|
||||||
rv = 0;
|
rv = 0;
|
||||||
|
|
||||||
if (buff) free(buff);
|
if (buff) free(buff);
|
||||||
if (file) sc_file_free(file);
|
|
||||||
if (clist) sc_file_free(clist);
|
if (clist) sc_file_free(clist);
|
||||||
|
sc_file_free(file);
|
||||||
|
|
||||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv);
|
||||||
}
|
}
|
||||||
|
@ -1744,7 +1742,6 @@ awp_remove_from_object_list( struct sc_pkcs15_card *p15card, struct sc_profile *
|
||||||
done:
|
done:
|
||||||
if (buff)
|
if (buff)
|
||||||
free(buff);
|
free(buff);
|
||||||
if (lst)
|
|
||||||
sc_file_free(lst);
|
sc_file_free(lst);
|
||||||
if (lst_file)
|
if (lst_file)
|
||||||
sc_file_free(lst_file);
|
sc_file_free(lst_file);
|
||||||
|
|
|
@ -63,15 +63,17 @@ static int
|
||||||
cosm_write_tokeninfo (struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
cosm_write_tokeninfo (struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
||||||
char *label, unsigned flags)
|
char *label, unsigned flags)
|
||||||
{
|
{
|
||||||
struct sc_context *ctx = p15card->card->ctx;
|
struct sc_context *ctx;
|
||||||
struct sc_file *file = NULL;
|
struct sc_file *file = NULL;
|
||||||
int rv;
|
int rv;
|
||||||
size_t sz;
|
size_t sz;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
|
|
||||||
if (!p15card || !profile)
|
if (!p15card || !p15card->card || !profile)
|
||||||
return SC_ERROR_INVALID_ARGUMENTS;
|
return SC_ERROR_INVALID_ARGUMENTS;
|
||||||
|
|
||||||
|
ctx = p15card->card->ctx;
|
||||||
|
|
||||||
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
|
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
|
||||||
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "cosm_write_tokeninfo() label '%s'; flags 0x%X", label, flags);
|
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "cosm_write_tokeninfo() label '%s'; flags 0x%X", label, flags);
|
||||||
if (sc_profile_get_file(profile, COSM_TITLE"-token-info", &file))
|
if (sc_profile_get_file(profile, COSM_TITLE"-token-info", &file))
|
||||||
|
|
|
@ -236,7 +236,6 @@ setcos_create_pin(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
||||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot set MF into the activated state");
|
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot set MF into the activated state");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pinfile)
|
|
||||||
sc_file_free(pinfile);
|
sc_file_free(pinfile);
|
||||||
|
|
||||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, r);
|
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, r);
|
||||||
|
|
|
@ -2059,7 +2059,7 @@ sc_profile_find_file_by_path(struct sc_profile *pro, const sc_path_t *path)
|
||||||
sc_log(ctx, "find profile file by path:%s", sc_print_path(path));
|
sc_log(ctx, "find profile file by path:%s", sc_print_path(path));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!path->len && !path->aid.len)
|
if (!path || (!path->len && !path->aid.len))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (fi = pro->ef_list; fi; fi = fi->next) {
|
for (fi = pro->ef_list; fi; fi = fi->next) {
|
||||||
|
|
|
@ -82,8 +82,9 @@ static scconf_item *scconf_item_find(scconf_parser * parser)
|
||||||
scconf_item *item;
|
scconf_item *item;
|
||||||
|
|
||||||
for (item = parser->block->items; item; item = item->next) {
|
for (item = parser->block->items; item; item = item->next) {
|
||||||
if (item->type == SCCONF_ITEM_TYPE_VALUE &&
|
if (item && item->type == SCCONF_ITEM_TYPE_VALUE
|
||||||
strcasecmp(item->key, parser->key) == 0) {
|
&& item->key && parser->key
|
||||||
|
&& strcasecmp(item->key, parser->key) == 0) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,6 +149,7 @@ scconf_item *scconf_item_add(scconf_context * config, scconf_block * block, scco
|
||||||
scconf_list_copy(dst->name, &parser.name);
|
scconf_list_copy(dst->name, &parser.name);
|
||||||
}
|
}
|
||||||
scconf_item_add_internal(&parser, type);
|
scconf_item_add_internal(&parser, type);
|
||||||
|
if (parser.current_item) {
|
||||||
switch (parser.current_item->type) {
|
switch (parser.current_item->type) {
|
||||||
case SCCONF_ITEM_TYPE_COMMENT:
|
case SCCONF_ITEM_TYPE_COMMENT:
|
||||||
parser.current_item->value.comment = strdup((const char *) data);
|
parser.current_item->value.comment = strdup((const char *) data);
|
||||||
|
@ -163,6 +165,9 @@ scconf_item *scconf_item_add(scconf_context * config, scconf_block * block, scco
|
||||||
scconf_list_copy((const scconf_list *) data, &parser.current_item->value.list);
|
scconf_list_copy((const scconf_list *) data, &parser.current_item->value.list);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* FIXME is it an error if item is NULL? */
|
||||||
|
}
|
||||||
return parser.current_item;
|
return parser.current_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,9 +57,11 @@ static void buf_addch(BUFHAN * bp, char ch)
|
||||||
bp->bufmax += 256;
|
bp->bufmax += 256;
|
||||||
bp->buf = (char *) realloc(bp->buf, bp->bufmax);
|
bp->buf = (char *) realloc(bp->buf, bp->bufmax);
|
||||||
}
|
}
|
||||||
|
if (bp->buf) {
|
||||||
bp->buf[bp->bufcur++] = ch;
|
bp->buf[bp->bufcur++] = ch;
|
||||||
bp->buf[bp->bufcur] = '\0';
|
bp->buf[bp->bufcur] = '\0';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int buf_nextch(BUFHAN * bp)
|
static int buf_nextch(BUFHAN * bp)
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,6 +38,7 @@ int main(int argc, char *argv[])
|
||||||
fwrite(outbuf, len, 1, stdout);
|
fwrite(outbuf, len, 1, stdout);
|
||||||
r = 0;
|
r = 0;
|
||||||
err:
|
err:
|
||||||
|
if (inf)
|
||||||
fclose(inf);
|
fclose(inf);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ int main(int argc, char* argv[])
|
||||||
if (r) {
|
if (r) {
|
||||||
fprintf(stderr, "Error: Failed to establish context: %s\n",
|
fprintf(stderr, "Error: Failed to establish context: %s\n",
|
||||||
sc_strerror(r));
|
sc_strerror(r));
|
||||||
return -1;
|
goto dnie_tool_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose > 1) {
|
if (verbose > 1) {
|
||||||
|
|
|
@ -113,7 +113,7 @@ static int load_object(const char * object_id, const char * object_file)
|
||||||
int r;
|
int r;
|
||||||
struct stat stat_buf;
|
struct stat stat_buf;
|
||||||
|
|
||||||
if((fp=fopen(object_file, "r"))==NULL){
|
if(!object_file || (fp=fopen(object_file, "r")) == NULL){
|
||||||
printf("Cannot open object file, %s %s\n",
|
printf("Cannot open object file, %s %s\n",
|
||||||
(object_file)?object_file:"", strerror(errno));
|
(object_file)?object_file:"", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -1296,7 +1296,6 @@ static int get_cert_info(sc_pkcs15_card_t *myp15card, sc_pkcs15_object_t *certob
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (cert)
|
|
||||||
sc_pkcs15_free_certificate(cert);
|
sc_pkcs15_free_certificate(cert);
|
||||||
if (othercert)
|
if (othercert)
|
||||||
sc_pkcs15_free_certificate(othercert);
|
sc_pkcs15_free_certificate(othercert);
|
||||||
|
|
|
@ -999,7 +999,7 @@ static int read_ssh_key(void)
|
||||||
fail:
|
fail:
|
||||||
printf("can't convert key: buffer too small\n");
|
printf("can't convert key: buffer too small\n");
|
||||||
fail2:
|
fail2:
|
||||||
if (outf != stdout)
|
if (outf && outf != stdout)
|
||||||
fclose(outf);
|
fclose(outf);
|
||||||
if (cert)
|
if (cert)
|
||||||
sc_pkcs15_free_certificate(cert);
|
sc_pkcs15_free_certificate(cert);
|
||||||
|
|
|
@ -305,7 +305,7 @@ static int cert2der(X509 *cert, u8 **value)
|
||||||
static int create_file_cert(sc_card_t *card)
|
static int create_file_cert(sc_card_t *card)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
int size;
|
int size = 0;
|
||||||
sc_path_t path;
|
sc_path_t path;
|
||||||
sc_file_t *file = NULL;
|
sc_file_t *file = NULL;
|
||||||
|
|
||||||
|
@ -313,12 +313,13 @@ static int create_file_cert(sc_card_t *card)
|
||||||
r = sc_select_file(card, &path, &file);
|
r = sc_select_file(card, &path, &file);
|
||||||
if(r) goto out;
|
if(r) goto out;
|
||||||
|
|
||||||
size = (file->size) - 32;
|
|
||||||
|
|
||||||
if(file)
|
if(file)
|
||||||
{
|
{
|
||||||
|
size = (file->size) - 32;
|
||||||
sc_file_free(file);
|
sc_file_free(file);
|
||||||
file = NULL;
|
file = NULL;
|
||||||
|
} else {
|
||||||
|
size = 2048;
|
||||||
}
|
}
|
||||||
|
|
||||||
sc_format_path("0002", &path);
|
sc_format_path("0002", &path);
|
||||||
|
@ -903,7 +904,6 @@ out:
|
||||||
sc_disconnect_card(card);
|
sc_disconnect_card(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx)
|
|
||||||
sc_release_context(ctx);
|
sc_release_context(ctx);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
Loading…
Reference in New Issue