Skip to content

Commit

Permalink
fixed a ton of compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Morgner authored and viktorTarasov committed Aug 3, 2013
1 parent 0781832 commit d218303
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 124 deletions.
2 changes: 0 additions & 2 deletions src/libopensc/card-belpic.c
Expand Up @@ -981,14 +981,12 @@ static int belpic_init(sc_card_t *card)
static int belpic_select_file(sc_card_t *card,
const sc_path_t *in_path, sc_file_t **file_out)
{
sc_context_t *ctx;
sc_apdu_t apdu;
u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
int r, pathlen;
sc_file_t *file = NULL;

assert(card != NULL && in_path != NULL);
ctx = card->ctx;
memcpy(path, in_path->value, in_path->len);
pathlen = in_path->len;

Expand Down
12 changes: 7 additions & 5 deletions src/libopensc/card-cardos.c
Expand Up @@ -864,7 +864,7 @@ cardos_compute_signature(sc_card_t *card, const u8 *data, size_t datalen,
* and www.crysys.hu/infsec/M40_Manual_E_2001_10.pdf)
*/

if (card->caps & SC_CARD_CAP_ONLY_RAW_HASH_STRIPPED){
if (card->caps & SC_CARD_CAP_ONLY_RAW_HASH_STRIPPED){
sc_log(ctx, "Forcing RAW_HASH_STRIPPED");
do_rsa_sig = 1;
}
Expand All @@ -873,7 +873,7 @@ cardos_compute_signature(sc_card_t *card, const u8 *data, size_t datalen,
do_rsa_sig = 1;
}
else {
//check the the algorithmIDs from the AlgorithmInfo
/* check the the algorithmIDs from the AlgorithmInfo */
int i;
for(i=0; i<algorithm_ids_in_tokeninfo_count;++i){
unsigned int id = algorithm_ids_in_tokeninfo[i];
Expand All @@ -884,10 +884,10 @@ cardos_compute_signature(sc_card_t *card, const u8 *data, size_t datalen,
}
}

//check if any operation was selected
/* check if any operation was selected */
if(do_rsa_sig == 0 && do_rsa_pure_sig == 0) {
//no operation selected. we just have to try both, for the lack of any better reasoning
sc_log(ctx, "I was unable to determine, wether this key can be used with RSA_SIG or RSA_PURE_SIG. I will just try both.");
/* no operation selected. we just have to try both, for the lack of any better reasoning */
sc_log(ctx, "I was unable to determine, whether this key can be used with RSA_SIG or RSA_PURE_SIG. I will just try both.");
do_rsa_sig = 1;
do_rsa_pure_sig = 1;
}
Expand Down Expand Up @@ -931,6 +931,8 @@ cardos_compute_signature(sc_card_t *card, const u8 *data, size_t datalen,
LOG_FUNC_RETURN(ctx, r);
return do_compute_signature(card, buf, buf_len, out, outlen);
}

LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
}

static int
Expand Down
4 changes: 1 addition & 3 deletions src/libopensc/card-epass2003.c
Expand Up @@ -858,7 +858,7 @@ epass2003_sm_free_wrapped_apdu(struct sc_card *card,
free(*sm_apdu);
*sm_apdu = NULL;

LOG_FUNC_RETURN(ctx, SC_SUCCESS);
LOG_FUNC_RETURN(ctx, rv);
}


Expand Down Expand Up @@ -1059,14 +1059,12 @@ epass2003_hook_file(struct sc_file *file, int inc)
static int
epass2003_select_fid_(struct sc_card *card, sc_path_t * in_path, sc_file_t ** file_out)
{
sc_context_t *ctx;
struct sc_apdu apdu;
u8 buf[SC_MAX_APDU_BUFFER_SIZE] = { 0 };
u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
int r, pathlen;
sc_file_t *file = NULL;

ctx = card->ctx;
epass2003_hook_path(in_path, 1);
memcpy(path, in_path->value, in_path->len);
pathlen = in_path->len;
Expand Down
4 changes: 1 addition & 3 deletions src/libopensc/card-jcop.c
Expand Up @@ -659,7 +659,7 @@ static int jcop_set_security_env(sc_card_t *card,
apdu.le = 0;
if (!env->flags & SC_SEC_ENV_ALG_REF_PRESENT)
return SC_ERROR_INVALID_ARGUMENTS;
if (!env->flags & SC_SEC_ENV_FILE_REF_PRESENT)
if (!(env->flags & SC_SEC_ENV_FILE_REF_PRESENT))
return SC_ERROR_INVALID_ARGUMENTS;
if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
if (env->key_ref_len > 1 || env->key_ref[0] != 0)
Expand Down Expand Up @@ -797,7 +797,6 @@ static int jcop_decipher(sc_card_t *card,
}

static int jcop_generate_key(sc_card_t *card, struct sc_cardctl_jcop_genkey *a) {
int modlen;
int r;
sc_apdu_t apdu;
u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
Expand Down Expand Up @@ -877,7 +876,6 @@ static int jcop_generate_key(sc_card_t *card, struct sc_cardctl_jcop_genkey *a)
if (rbuf[0] != 0x4) {
return SC_ERROR_INVALID_DATA;
}
modlen=rbuf[1] * 32;
if (a->pubkey_len < rbuf[1])
return SC_ERROR_BUFFER_TOO_SMALL;
a->pubkey_len=rbuf[1] * 4;
Expand Down
4 changes: 1 addition & 3 deletions src/libopensc/card-miocos.c
Expand Up @@ -320,7 +320,7 @@ static int miocos_get_acl(sc_card_t *card, sc_file_t *file)
u8 rbuf[256];
const u8 *seq = rbuf;
size_t left;
int acl_types[16], r;
int r;
unsigned int i;

sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x01, 0x01);
Expand All @@ -331,8 +331,6 @@ static int miocos_get_acl(sc_card_t *card, sc_file_t *file)
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
if (apdu.resplen == 0)
return sc_check_sw(card, apdu.sw1, apdu.sw2);
for (i = 0; i < 16; i++)
acl_types[i] = SC_AC_KEY_REF_NONE;
left = apdu.resplen;
seq = sc_asn1_skip_tag(card->ctx, &seq, &left,
SC_ASN1_SEQUENCE | SC_ASN1_CONS, &left);
Expand Down
2 changes: 1 addition & 1 deletion src/libopensc/card-myeid.c
Expand Up @@ -1150,7 +1150,7 @@ static int myeid_get_info(struct sc_card *card, u8 *rbuf, size_t buflen)
card->version.fw_major = rbuf[5] * 10 + rbuf[6];
card->version.fw_minor = rbuf[7];
/* add version to name */
sprintf(nameBuf, "%s %d.%d.%d", card->name, rbuf[5], rbuf[6], rbuf[7]);
sprintf((char *) nameBuf, "%s %d.%d.%d", card->name, rbuf[5], rbuf[6], rbuf[7]);
card->name = nameBuf;
//card->driver->name
LOG_FUNC_RETURN(card->ctx, r);
Expand Down
9 changes: 2 additions & 7 deletions src/libopensc/card-openpgp.c
Expand Up @@ -549,7 +549,6 @@ pgp_set_blob(struct blob *blob, const u8 *data, size_t len)
static void
pgp_attach_acl(sc_card_t *card, sc_file_t *file, struct do_info *info)
{
sc_acl_entry_t *acl;
unsigned int method = SC_AC_NONE;
unsigned long key_ref = SC_AC_KEY_REF_NONE;

Expand Down Expand Up @@ -1676,7 +1675,6 @@ static int
pgp_parse_and_set_pubkey_output(sc_card_t *card, u8* data, size_t data_len,
sc_cardctl_openpgp_keygen_info_t *key_info)
{
unsigned int blob_id;
time_t ctime = 0;
u8 *in = data;
u8 *modulus = NULL;
Expand Down Expand Up @@ -1772,10 +1770,7 @@ static int pgp_update_card_algorithms(sc_card_t *card, sc_cardctl_openpgp_keygen
**/
static int pgp_gen_key(sc_card_t *card, sc_cardctl_openpgp_keygen_info_t *key_info)
{
struct pgp_priv_data *priv = DRVDATA(card);
struct blob *algo_blob;
sc_apdu_t apdu;
unsigned int modulus_bitlen;
/* Temporary variables to hold APDU params */
u8 apdu_case;
u8 *apdu_data;
Expand All @@ -1784,6 +1779,8 @@ static int pgp_gen_key(sc_card_t *card, sc_cardctl_openpgp_keygen_info_t *key_in

LOG_FUNC_CALLED(card->ctx);

/* FIXME the compilers doesn't assure that the buffers set here as
* apdu_data are present until the end of the function */
/* Set Control Reference Template for key */
if (key_info->keytype == SC_OPENPGP_KEY_SIGN)
apdu_data = (unsigned char *) "\xb6";
Expand Down Expand Up @@ -1921,7 +1918,6 @@ static int
pgp_build_extended_header_list(sc_card_t *card, sc_cardctl_openpgp_keystore_info_t *key_info,
u8 **result, size_t *resultlen)
{
struct pgp_priv_data *priv = DRVDATA(card);
sc_context_t *ctx = card->ctx;
/* The Cardholder private key template (7F48) part */
const size_t max_prtem_len = 7*(1 + 3); /* 7 components */
Expand Down Expand Up @@ -2078,7 +2074,6 @@ pgp_build_extended_header_list(sc_card_t *card, sc_cardctl_openpgp_keystore_info
**/
static int pgp_store_key(sc_card_t *card, sc_cardctl_openpgp_keystore_info_t *key_info)
{
struct pgp_priv_data *priv = DRVDATA(card);
sc_context_t *ctx = card->ctx;
sc_cardctl_openpgp_keygen_info_t pubkey;
u8 *data;
Expand Down
6 changes: 1 addition & 5 deletions src/libopensc/card-sc-hsm.c
Expand Up @@ -137,7 +137,6 @@ static int sc_hsm_match_card(struct sc_card *card)
static int sc_hsm_pin_info(sc_card_t *card, struct sc_pin_cmd_data *data,
int *tries_left)
{
sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
sc_apdu_t apdu;
int r;

Expand Down Expand Up @@ -234,7 +233,6 @@ static int sc_hsm_update_binary(sc_card_t *card,
{
sc_context_t *ctx = card->ctx;
sc_apdu_t apdu;
u8 recvbuf[SC_MAX_APDU_BUFFER_SIZE];
u8 *cmdbuff, *p;
size_t len;
int r;
Expand Down Expand Up @@ -621,7 +619,7 @@ static int sc_hsm_get_serialnr(sc_card_t *card, sc_serial_number_t *serial)
static int sc_hsm_initialize(sc_card_t *card, sc_cardctl_sc_hsm_init_param_t *params)
{
sc_context_t *ctx = card->ctx;
int r, i;
int r;
sc_apdu_t apdu;
u8 ibuff[50], *p;

Expand Down Expand Up @@ -760,7 +758,6 @@ static int sc_hsm_unwrap_key(sc_card_t *card, sc_cardctl_sc_hsm_wrapped_key_t *p
{
sc_context_t *ctx = card->ctx;
sc_apdu_t apdu;
u8 status[MAX_EXT_APDU_LENGTH];
int r;

LOG_FUNC_CALLED(card->ctx);
Expand Down Expand Up @@ -888,7 +885,6 @@ static int sc_hsm_init_pin(sc_card_t *card, sc_cardctl_pkcs11_init_pin_t *params

static int sc_hsm_generate_keypair(sc_card_t *card, sc_cardctl_sc_hsm_keygen_info_t *keyinfo)
{
sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
u8 rbuf[1024];
int r;
sc_apdu_t apdu;
Expand Down
29 changes: 13 additions & 16 deletions src/libopensc/pkcs15-sc-hsm.c
Expand Up @@ -147,13 +147,13 @@ int sc_pkcs15emu_sc_hsm_decode_cvc(sc_pkcs15_card_t * p15card,

sc_format_asn1_entry(asn1_req , &asn1_authreq, NULL, 0);

// sc_asn1_print_tags(*buf, *buflen);
/* sc_asn1_print_tags(*buf, *buflen); */

tbuf = *buf;
r = sc_asn1_read_tag(&tbuf, *buflen, &cla, &tag, &taglen);
LOG_TEST_RET(card->ctx, r, "Could not decode card verifiable certificate");

// Determine if we deal with an authenticated request, plain request or certificate
/* Determine if we deal with an authenticated request, plain request or certificate */
if ((cla == (SC_ASN1_TAG_APPLICATION|SC_ASN1_TAG_CONSTRUCTED)) && (tag == 7)) {
r = sc_asn1_decode(card->ctx, asn1_req, *buf, *buflen, buf, buflen);
} else {
Expand All @@ -179,8 +179,6 @@ int sc_pkcs15emu_sc_hsm_encode_cvc(sc_pkcs15_card_t * p15card,
struct sc_asn1_entry asn1_cvcert[C_ASN1_CVCERT_SIZE];
struct sc_asn1_entry asn1_cvc_body[C_ASN1_CVC_BODY_SIZE];
struct sc_asn1_entry asn1_cvc_pubkey[C_ASN1_CVC_PUBKEY_SIZE];
unsigned int cla,tag;
size_t taglen;
size_t lenchr;
size_t lencar;
int r;
Expand Down Expand Up @@ -274,7 +272,7 @@ static int sc_pkcs15emu_sc_hsm_add_pubkey(sc_pkcs15_card_t *p15card, sc_pkcs15_p
size_t cvclen;
int r;

// EF.CERT is selected
/* EF.CERT is selected */
r = sc_read_binary(p15card->card, 0, efbin, sizeof(efbin), 0);
LOG_TEST_RET(card->ctx, r, "Could not read CSR from EF");

Expand All @@ -286,7 +284,7 @@ static int sc_pkcs15emu_sc_hsm_add_pubkey(sc_pkcs15_card_t *p15card, sc_pkcs15_p
LOG_TEST_RET(card->ctx, r, "Could decode certificate signing request");

if (cvc.publicPoint || cvc.publicPointlen) {
// ToDo implement support for EC Public Keys
/* ToDo implement support for EC Public Keys */
return SC_SUCCESS;
} else {
pubkey.algorithm = SC_ALGORITHM_RSA;
Expand Down Expand Up @@ -330,7 +328,7 @@ static int sc_pkcs15emu_sc_hsm_add_prkd(sc_pkcs15_card_t * p15card, u8 keyid) {
u8 efbin[512];
u8 *ptr;
size_t len;
int r, i;
int r;

fid[0] = PRKD_PREFIX;
fid[1] = keyid;
Expand Down Expand Up @@ -393,9 +391,9 @@ static int sc_pkcs15emu_sc_hsm_add_prkd(sc_pkcs15_card_t * p15card, u8 keyid) {
return SC_SUCCESS;
}

if (efbin[0] == 0x67) { // Decode CSR and create public key object
if (efbin[0] == 0x67) { /* Decode CSR and create public key object */
sc_pkcs15emu_sc_hsm_add_pubkey(p15card, key_info, prkd.label);
return SC_SUCCESS; // Ignore any errors
return SC_SUCCESS; /* Ignore any errors */
}

if (efbin[0] != 0x30) {
Expand Down Expand Up @@ -432,7 +430,7 @@ static int sc_pkcs15emu_sc_hsm_add_dcod(sc_pkcs15_card_t * p15card, u8 id) {
u8 efbin[512];
const u8 *ptr;
size_t len;
int r, i;
int r;

fid[0] = DCOD_PREFIX;
fid[1] = id;
Expand Down Expand Up @@ -481,7 +479,7 @@ static int sc_pkcs15emu_sc_hsm_add_cd(sc_pkcs15_card_t * p15card, u8 id) {
u8 efbin[512];
const u8 *ptr;
size_t len;
int r, i;
int r;

fid[0] = CD_PREFIX;
fid[1] = id;
Expand Down Expand Up @@ -532,7 +530,6 @@ static int sc_pkcs15emu_sc_hsm_init (sc_pkcs15_card_t * p15card)
struct sc_app_info *appinfo;
struct sc_pkcs15_auth_info pin_info;
struct sc_pkcs15_object pin_obj;
u8 fid[2];
u8 efbin[512];
u8 *ptr;
size_t len;
Expand All @@ -558,15 +555,15 @@ static int sc_pkcs15emu_sc_hsm_init (sc_pkcs15_card_t * p15card)
r = sc_select_file(card, &path, &file);
LOG_TEST_RET(card->ctx, r, "Could not select SmartCard-HSM application");

p15card->card->version.hw_major = 24; // JCOP 2.4.1r3
p15card->card->version.hw_major = 24; /* JCOP 2.4.1r3 */
p15card->card->version.hw_minor = 13;
p15card->card->version.fw_major = file->prop_attr[file->prop_attr_len - 2];
p15card->card->version.fw_minor = file->prop_attr[file->prop_attr_len - 1];

sc_file_free(file);

// Read device certificate to determine serial number
sc_path_set(&path, SC_PATH_TYPE_FILE_ID, "\x2F\x02", 2, 0, 0);
/* Read device certificate to determine serial number */
sc_path_set(&path, SC_PATH_TYPE_FILE_ID, (u8 *) "\x2F\x02", 2, 0, 0);
r = sc_select_file(card, &path, &file);
LOG_TEST_RET(card->ctx, r, "Could not select EF.C_DevAut");
sc_file_free(file);
Expand All @@ -581,7 +578,7 @@ static int sc_pkcs15emu_sc_hsm_init (sc_pkcs15_card_t * p15card)
r = sc_pkcs15emu_sc_hsm_decode_cvc(p15card, (const u8 **)&ptr, &len, &devcert);
LOG_TEST_RET(card->ctx, r, "Could not decode EF.C_DevAut");

len = strlen(devcert.chr); // Strip last 5 digit sequence number from CHR
len = strlen(devcert.chr); /* Strip last 5 digit sequence number from CHR */
assert(len >= 8);
len -= 5;

Expand Down
16 changes: 4 additions & 12 deletions src/pkcs15init/pkcs15-iasecc.c
Expand Up @@ -324,6 +324,9 @@ iasecc_file_convert_acls(struct sc_context *ctx, struct sc_profile *profile, str
int ii;

for (ii=0; ii<SC_MAX_AC_OPS;ii++) {
/* FIXME the acl object must not be modified, it is only defined in
* sc_file_get_acl_entry. Accessing it here means we have a race
* condition. */
struct sc_acl_entry *acl = sc_file_get_acl_entry(file, ii);

if (acl) {
Expand Down Expand Up @@ -1314,8 +1317,8 @@ iasecc_pkcs15_delete_object (struct sc_profile *profile, struct sc_pkcs15_card *

switch(object->type & SC_PKCS15_TYPE_CLASS_MASK) {
case SC_PKCS15_TYPE_PUBKEY:
sc_log(ctx, "Ignore delete of SDO-PubKey(ref:%X) '%s', path %s", key_ref, object->label, sc_print_path(path));
key_ref = ((struct sc_pkcs15_pubkey_info *)object->data)->key_reference;
sc_log(ctx, "Ignore delete of SDO-PubKey(ref:%X) '%s', path %s", key_ref, object->label, sc_print_path(path));
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
case SC_PKCS15_TYPE_PRKEY:
sc_log(ctx, "delete PrivKey '%s', path %s", object->label, sc_print_path(path));
Expand Down Expand Up @@ -1655,12 +1658,9 @@ iasecc_store_data_object(struct sc_pkcs15_card *p15card, struct sc_profile *prof
LOG_TEST_RET(ctx, nn_objs, "IasEcc get pkcs15 DATA objects error");

for(indx = 1; indx < MAX_DATA_OBJS; indx++) {
struct sc_path fpath;

rv = iasecc_pkcs15_new_file(profile, card, SC_PKCS15_TYPE_DATA_OBJECT, indx, &file);
LOG_TEST_RET(ctx, rv, "iasecc_store_data_object() pkcs15 new DATA file error");

fpath = file->path;
for (ii=0; ii<nn_objs; ii++) {
struct sc_pkcs15_data_info *info = (struct sc_pkcs15_data_info *)p15objects[ii]->data;
int file_id = info->path.value[info->path.len - 2] * 0x100 + info->path.value[info->path.len - 1];
Expand Down Expand Up @@ -1788,14 +1788,6 @@ iasecc_emu_store_data(struct sc_pkcs15_card *p15card, struct sc_profile *profile
}


static int
iasecc_emu_update_tokeninfo(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
struct sc_pkcs15_tokeninfo *tinfo)
{
LOG_FUNC_RETURN(p15card->card->ctx, SC_SUCCESS);
}


static struct sc_pkcs15init_operations
sc_pkcs15init_iasecc_operations = {
iasecc_pkcs15_erase_card,
Expand Down

0 comments on commit d218303

Please sign in to comment.