fixed NULL dereference (or warning thereof)

This commit is contained in:
Frank Morgner 2015-02-04 19:19:57 +01:00
parent 8d902d1ed3
commit a3fc62f79f
13 changed files with 53 additions and 39 deletions

View File

@ -2110,14 +2110,16 @@ static int
authentic_sm_acl_init (struct sc_card *card, struct sm_info *sm_info, int cmd,
unsigned char *resp, size_t *resp_len)
{
struct sc_context *ctx = card->ctx;
struct sm_type_params_gp *params_gp = &sm_info->session.gp.params;
struct sc_context *ctx;
struct sm_type_params_gp *params_gp;
struct sc_remote_data rdata;
int rv;
sc_log(ctx, "called; command 0x%X\n", cmd);
if (!card || !sm_info || !resp || !resp_len)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
return SC_ERROR_INVALID_ARGUMENTS;
ctx = card->ctx;
params_gp = &sm_info->session.gp.params;
if (!card->sm_ctx.module.ops.initialize || !card->sm_ctx.module.ops.get_apdus)
LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);

View File

@ -1141,7 +1141,7 @@ epass2003_select_fid(struct sc_card *card, unsigned int id_hi, unsigned int id_l
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
/* update cache */
if (file->type == SC_FILE_TYPE_DF) {
if (file && file->type == SC_FILE_TYPE_DF) {
card->cache.current_path.type = SC_PATH_TYPE_PATH;
card->cache.current_path.value[0] = 0x3f;
card->cache.current_path.value[1] = 0x00;

View File

@ -3324,7 +3324,8 @@ iasecc_read_public_key(struct sc_card *card, unsigned type,
rv = sc_pkcs15_encode_pubkey_rsa(ctx, &rsa_key, out, out_len);
LOG_TEST_RET(ctx, rv, "failed to read public key: cannot encode RSA public key");
sc_log(ctx, "encoded public key: %s", sc_dump_hex(*out, *out_len));
if (out && out_len)
sc_log(ctx, "encoded public key: %s", sc_dump_hex(*out, *out_len));
if (bn[0].data)
free(bn[0].data);

View File

@ -419,6 +419,8 @@ static int load_special_files(sc_card_t * card)
if (dfi && dfi->rule_file)
return 0; /* yes. */
clear_special_files(dfi);
if (!dfi)
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INTERNAL);
/* Read rule file. Note that we bypass our cache here. */
r = select_part(card, MCRD_SEL_EF, EF_Rule, NULL);

View File

@ -985,7 +985,8 @@ iasecc_sdo_encode_create(struct sc_context *ctx, struct iasecc_sdo *sdo, unsigne
rv = sc_asn1_encode(ctx, asn1_create_data, out, &out_len);
LOG_TEST_RET(ctx, rv, "Encode create data error");
sc_debug(ctx, SC_LOG_DEBUG_ASN1,"Create data: %s", sc_dump_hex(*out, out_len));
if (out)
sc_debug(ctx, SC_LOG_DEBUG_ASN1,"Create data: %s", sc_dump_hex(*out, out_len));
LOG_FUNC_RETURN(ctx, out_len);
}

View File

@ -37,12 +37,15 @@
static int
sm_save_sc_context (struct sc_card *card, struct sm_info *sm_info)
{
struct sc_context *ctx = card->ctx;
struct sc_card_cache *cache = &card->cache;
struct sc_context *ctx;
struct sc_card_cache *cache;
if (!card || !sm_info)
return SC_ERROR_INVALID_ARGUMENTS;
ctx = card->ctx;
cache = &card->cache;
sc_log(ctx, "SM save context: cache(valid:%i,current_df:%p)", cache->valid, cache->current_df);
if (cache->valid && cache->current_df) {
sm_info->current_path_df = cache->current_df->path;

View File

@ -61,7 +61,7 @@ sc_pkcs15_read_data_object(struct sc_pkcs15_card *p15card,
sc_der_copy(&der, &info->data);
data_object = calloc(sizeof(struct sc_pkcs15_data), 1);
if (!data_object && !der.value)
if (!data_object || !der.value)
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot allocate memory for data object");
data_object->data = der.value;

View File

@ -426,7 +426,7 @@ static int sc_pkcs15emu_sc_hsm_get_ec_public_key(struct sc_context *ctx, sc_cvc_
int sc_pkcs15emu_sc_hsm_get_public_key(struct sc_context *ctx, sc_cvc_t *cvc, struct sc_pkcs15_pubkey *pubkey)
{
if (cvc->publicPoint || cvc->publicPointlen) {
if (cvc->publicPoint && cvc->publicPointlen) {
return sc_pkcs15emu_sc_hsm_get_ec_public_key(ctx, cvc, pubkey);
} else {
return sc_pkcs15emu_sc_hsm_get_rsa_public_key(ctx, cvc, pubkey);

View File

@ -573,16 +573,20 @@ iasecc_sdo_allocate_pubkey(struct sc_profile *profile, struct sc_card *card, str
static int
iasecc_sdo_convert_to_file(struct sc_card *card, struct iasecc_sdo *sdo, struct sc_file **out)
{
struct sc_context *ctx = card->ctx;
struct sc_file *file = sc_file_new();
struct sc_context *ctx;
struct sc_file *file;
unsigned ii;
int rv;
if (!card || !sdo)
return SC_ERROR_INVALID_ARGUMENTS;
ctx = card->ctx;
LOG_FUNC_CALLED(ctx);
if (file == NULL)
file = sc_file_new();
if (!file)
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
else if (!card || !sdo)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
sc_log(ctx, "SDO class 0x%X", sdo->sdo_class);
@ -1761,8 +1765,7 @@ iasecc_store_data_object(struct sc_pkcs15_card *p15card, struct sc_profile *prof
if (parent)
sc_file_free(parent);
if (file)
sc_file_free(file);
sc_file_free(file);
if (cfile)
sc_file_free(cfile);

View File

@ -1712,6 +1712,8 @@ sc_pkcs15init_store_data_object(struct sc_pkcs15_card *p15card,
unsigned int tid = 0x01;
LOG_FUNC_CALLED(ctx);
if (!profile)
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Missing profile");
label = args->label;
if (!args->id.len) {
@ -2673,6 +2675,9 @@ sc_pkcs15init_update_any_df(struct sc_pkcs15_card *p15card,
int update_odf = is_new, r = 0;
LOG_FUNC_CALLED(ctx);
if (!df)
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "DF missing");
r = sc_profile_get_file_by_path(profile, &df->path, &file);
LOG_TEST_RET(ctx, r, "Failed get file path");
if (file == NULL)

View File

@ -152,14 +152,12 @@ sm_iasecc_get_apdu_create_file(struct sc_context *ctx, struct sm_info *sm_info,
int rv = 0;
LOG_FUNC_CALLED(ctx);
if (!cmd_data || !cmd_data->data || !rdata || !rdata->alloc)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
sc_log(ctx, "SM get 'CREATE FILE' APDU: FCP(%i) %s", cmd_data->size, sc_dump_hex(cmd_data->data,cmd_data->size));
if (!cmd_data || !cmd_data->data)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
if (!rdata || !rdata->alloc)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
rv = rdata->alloc(rdata, &rapdu);
LOG_TEST_RET(ctx, rv, "SM get 'UPDATE BINARY' APDUs: cannot allocate remote APDU");
@ -229,14 +227,11 @@ sm_iasecc_get_apdu_verify_pin(struct sc_context *ctx, struct sm_info *sm_info, s
int rv;
LOG_FUNC_CALLED(ctx);
if (!pin_data || !rdata || !rdata->alloc)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
sc_log(ctx, "SM get 'VERIFY PIN' APDU: ", pin_data->pin_reference);
if (!pin_data)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
if (!rdata || !rdata->alloc)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
rv = rdata->alloc(rdata, &rapdu);
LOG_TEST_RET(ctx, rv, "SM get 'VERIFY PIN' APDUs: cannot allocate remote APDU");
@ -272,14 +267,12 @@ sm_iasecc_get_apdu_reset_pin(struct sc_context *ctx, struct sm_info *sm_info, st
int rv;
LOG_FUNC_CALLED(ctx);
if (!pin_data || !rdata || !rdata->alloc)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
sc_log(ctx, "SM get 'RESET PIN' APDU; reference %i", pin_data->pin_reference);
if (!pin_data)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
if (!rdata || !rdata->alloc)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
rv = rdata->alloc(rdata, &rapdu);
LOG_TEST_RET(ctx, rv, "SM get 'RESET PIN' APDUs: cannot allocate remote APDU");

View File

@ -168,9 +168,14 @@ static int load_cert(const char * cert_id, const char * cert_file,
size_t derlen;
int r;
if (!cert_file) {
printf("Missing cert file\n");
return -1;
}
if((fp=fopen(cert_file, "r"))==NULL){
printf("Cannot open cert file, %s %s\n",
cert_file?cert_file:"", strerror(errno));
cert_file, strerror(errno));
return -1;
}
if (compress) { /* file is gziped already */

View File

@ -1002,8 +1002,7 @@ static int read_ssh_key(void)
fclose(outf);
if (cert)
sc_pkcs15_free_certificate(cert);
else if (pubkey)
sc_pkcs15_free_pubkey(pubkey);
sc_pkcs15_free_pubkey(pubkey);
return 0;
fail: