Skip to content

Commit

Permalink
fixed compiler warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Morgner <morgner@informatik.hu-berlin.de>
  • Loading branch information
Frank Morgner committed Mar 2, 2014
1 parent a399905 commit 0b567db
Show file tree
Hide file tree
Showing 29 changed files with 73 additions and 89 deletions.
2 changes: 1 addition & 1 deletion src/libopensc/asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ static int asn1_decode_se_info(sc_context_t *ctx, const u8 *obj, size_t objlen,
ret = SC_SUCCESS;
err:
if (ret != SC_SUCCESS) {
int i;
size_t i;
for (i = 0; i < idx; i++)
if (ses[i])
free(ses[i]);
Expand Down
8 changes: 4 additions & 4 deletions src/libopensc/card-authentic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ static int
authentic_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data, int *tries_left)
{
struct sc_context *ctx = card->ctx;
int rv;
int rv = SC_ERROR_INTERNAL;

LOG_FUNC_CALLED(ctx);
sc_log(ctx, "PIN-CMD:%X,PIN(type:%X,ret:%i)", data->cmd, data->pin_type, data->pin_reference);
Expand Down Expand Up @@ -2284,9 +2284,9 @@ authentic_sm_free_wrapped_apdu(struct sc_card *card, struct sc_apdu *plain, stru
}

if ((*sm_apdu)->data)
free((*sm_apdu)->data);
free((unsigned char *) (*sm_apdu)->data);
if ((*sm_apdu)->resp)
free((*sm_apdu)->resp);
free((unsigned char *) (*sm_apdu)->resp);

free(*sm_apdu);
*sm_apdu = NULL;
Expand Down Expand Up @@ -2337,7 +2337,7 @@ authentic_sm_get_wrapped_apdu(struct sc_card *card, struct sc_apdu *plain, struc
if (!apdu->data)
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
if (plain->data && plain->datalen)
memcpy(apdu->data, plain->data, plain->datalen);
memcpy((unsigned char *) apdu->data, plain->data, plain->datalen);

apdu->resp = calloc (1, plain->resplen + 32);
if (!apdu->resp)
Expand Down
2 changes: 1 addition & 1 deletion src/libopensc/card-cardos.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ cardos_compute_signature(sc_card_t *card, const u8 *data, size_t datalen,
}
else {
/* check the the algorithmIDs from the AlgorithmInfo */
int i;
size_t i;
for(i=0; i<algorithm_ids_in_tokeninfo_count;++i){
unsigned int id = algorithm_ids_in_tokeninfo[i];
if(id == 0x86 || id == 0x88)
Expand Down
24 changes: 11 additions & 13 deletions src/libopensc/card-dnie.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "cwa-dnie.h"
#include "user-interface.h"

#ifdef ENABLE_SM
#if ENABLE_SM && 0
static int dnie_sm_get_wrapped_apdu(sc_card_t *card, sc_apdu_t *apdu, sc_apdu_t **sm_apdu);
static int dnie_sm_free_and_unwrap_apdu(sc_card_t *card, sc_apdu_t *apdu, sc_apdu_t **sm_apdu);
#endif
Expand Down Expand Up @@ -551,7 +551,7 @@ static int dnie_init(struct sc_card *card)
/** Secure messaging initialization section **/
memset(&(card->sm_ctx), 0, sizeof(sm_context_t));
/* setup dnie sm driver *im*properly */
/* TODO: at the moment this is a wild guess, based on card-authentic.c */
/* FIXME: at the moment this is a wild guess, based on card-authentic.c */
card->sm_ctx.ops.get_sm_apdu = NULL; /*dnie_sm_get_wrapped_apdu;*/
card->sm_ctx.ops.free_sm_apdu = NULL; /*dnie_sm_free_and_unwrap_apdu;*/
#endif
Expand Down Expand Up @@ -951,7 +951,6 @@ static int dnie_select_file(struct sc_card *card,
char pbuf[SC_MAX_PATH_STRING_SIZE];
u8 *path = pathbuf;
size_t pathlen;
int cached=0;

sc_file_t *file = NULL;
int res = SC_SUCCESS;
Expand Down Expand Up @@ -1006,7 +1005,7 @@ static int dnie_select_file(struct sc_card *card,
* - path starts with cache
* remember that only DF's are cached
*/
cached = dnie_check_path(card, &path, &pathlen, file_out != NULL);
dnie_check_path(card, &path, &pathlen, file_out != NULL);
if (pathlen == 0) {
/* request to select_file on current df */
sc_log(ctx,"Cache hit: already on cached DF");
Expand Down Expand Up @@ -1954,9 +1953,9 @@ static int dnie_process_fci(struct sc_card *card,
*/
static int dnie_pin_change(struct sc_card *card, struct sc_pin_cmd_data * data)
{
int res=SC_SUCCESS;
LOG_FUNC_CALLED(card->ctx);
#ifdef ENABLE_SM
int res;
LOG_FUNC_CALLED(card->ctx);
/* Ensure that secure channel is established from reset */
res = cwa_create_secure_channel(card, GET_DNIE_PRIV_DATA(card)->cwa_provider, CWA_SM_COLD);
LOG_TEST_RET(card->ctx, res, "Establish SM failed");
Expand Down Expand Up @@ -2103,7 +2102,7 @@ static int dnie_pin_cmd(struct sc_card *card,
LOG_FUNC_RETURN(card->ctx, res);
}

#ifdef ENABLE_SM
#if ENABLE_SM && 0
static int dnie_sm_wrap_apdu(struct sc_card *card, struct sc_apdu *plain, struct sc_apdu *wrapped)
{
int res = SC_SUCCESS;
Expand All @@ -2126,7 +2125,7 @@ static int dnie_sm_wrap_apdu(struct sc_card *card, struct sc_apdu *plain, struct
wrapped->le = plain->le;
wrapped->control = plain->control;
wrapped->flags = plain->flags;
memcpy(wrapped->data, plain->data, plain->datalen);
memcpy((unsigned char *) wrapped->data, plain->data, plain->datalen);

/* if SM is ON, ensure resp exists, and force getResponse() */
if (provider->status.session.state == CWA_SM_ACTIVE) {
Expand All @@ -2139,6 +2138,7 @@ static int dnie_sm_wrap_apdu(struct sc_card *card, struct sc_apdu *plain, struct
LOG_FUNC_RETURN(ctx, res);
}

#if ENABLE_SM && 0
static int dnie_sm_get_wrapped_apdu(sc_card_t *card, sc_apdu_t *plain, sc_apdu_t **sm_apdu)
{
struct sc_context *ctx = card->ctx;
Expand Down Expand Up @@ -2172,17 +2172,15 @@ static int dnie_sm_get_wrapped_apdu(sc_card_t *card, sc_apdu_t *plain, sc_apdu_t
*sm_apdu = apdu;
LOG_FUNC_RETURN(ctx, rv);
}
#endif

static int dnie_sm_unwrap_apdu(sc_card_t *card, sc_apdu_t *wrapped, sc_apdu_t *plain)
{
int res = SC_SUCCESS;
struct sc_context *ctx = card->ctx;
cwa_provider_t *provider = NULL;

LOG_FUNC_CALLED(ctx);

provider = GET_DNIE_PRIV_DATA(card)->cwa_provider;

/* parse response and handle SM related errors */
res = sc_check_sw(card, wrapped->sw1, wrapped->sw2);

Expand Down Expand Up @@ -2217,10 +2215,10 @@ static int dnie_sm_free_and_unwrap_apdu(sc_card_t *card, sc_apdu_t *plain, sc_ap
rv = dnie_sm_unwrap_apdu(card, *sm_apdu, plain);

if ((*sm_apdu)->data)
free((*sm_apdu)->data);
free((unsigned char *) (*sm_apdu)->data);
if ((*sm_apdu)->resp)
free((*sm_apdu)->resp);
free(*sm_apdu);
free((unsigned char *) *sm_apdu);
*sm_apdu = NULL;

LOG_FUNC_RETURN(ctx, SC_SUCCESS);
Expand Down
2 changes: 1 addition & 1 deletion src/libopensc/card-epass2003.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ epass2003_sm_free_wrapped_apdu(struct sc_card *card,
rv = epass2003_sm_unwrap_apdu(card, *sm_apdu, plain);

if ((*sm_apdu)->data)
free((*sm_apdu)->data);
free((unsigned char *) (*sm_apdu)->data);
if ((*sm_apdu)->resp)
free((*sm_apdu)->resp);
free(*sm_apdu);
Expand Down
16 changes: 0 additions & 16 deletions src/libopensc/card-flex.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,7 @@ cyberflex_construct_file_attrs(sc_card_t *card, const sc_file_t *file,
u8 *buf, size_t *buflen)
{
u8 *p = buf;
int i;
size_t size = file->size;
int ops[6];

/* cyberflex wants input parameters length added */
switch (file->type) {
Expand Down Expand Up @@ -903,20 +901,6 @@ cyberflex_construct_file_attrs(sc_card_t *card, const sc_file_t *file,
return -1;
}
p[5] = 0x01; /* status?? */
for (i = 0; i < 6; i++)
ops[i] = -1;
if (file->type == SC_FILE_TYPE_DF) {
ops[0] = SC_AC_OP_LIST_FILES;
ops[2] = SC_AC_OP_DELETE;
ops[3] = SC_AC_OP_CREATE;
} else {
ops[0] = SC_AC_OP_READ;
ops[1] = SC_AC_OP_UPDATE;
ops[2] = SC_AC_OP_READ;
ops[3] = SC_AC_OP_UPDATE;
ops[4] = SC_AC_OP_REHABILITATE;
ops[5] = SC_AC_OP_INVALIDATE;
}
p[6] = p[7] = 0;

*buflen = 16;
Expand Down
8 changes: 5 additions & 3 deletions src/libopensc/card-iasecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2219,12 +2219,14 @@ iasecc_keyset_change(struct sc_card *card, struct sc_pin_cmd_data *data, int *tr

update.fields[0].parent_tag = IASECC_SDO_KEYSET_TAG;
update.fields[0].tag = IASECC_SDO_KEYSET_TAG_MAC;
update.fields[0].value = data->pin2.data;
/* FIXME race condition */
update.fields[0].value = (unsigned char *) data->pin2.data;
update.fields[0].size = 16;

update.fields[1].parent_tag = IASECC_SDO_KEYSET_TAG;
update.fields[1].tag = IASECC_SDO_KEYSET_TAG_ENC;
update.fields[1].value = data->pin2.data + 16;
/* FIXME race condition */
update.fields[1].value = (unsigned char *) data->pin2.data + 16;
update.fields[1].size = 16;

rv = iasecc_sm_sdo_update(card, (scb & IASECC_SCB_METHOD_MASK_REF), &update);
Expand Down Expand Up @@ -3110,7 +3112,7 @@ iasecc_compute_signature_dst(struct sc_card *card,
size_t offs = 0, hash_len = 0;
unsigned char sbuf[SC_MAX_APDU_BUFFER_SIZE];
unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
int rv;
int rv = SC_ERROR_INTERNAL;

LOG_FUNC_CALLED(ctx);
sc_log(ctx, "iasecc_compute_signature_dst() input length %i", in_len);
Expand Down
2 changes: 1 addition & 1 deletion src/libopensc/card-jcop.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ static int jcop_set_security_env(sc_card_t *card,
if (tmp.algorithm_flags & SC_ALGORITHM_RSA_HASH_MD5)
tmp.algorithm_ref |= 0x20;

memcpy(env, &tmp, sizeof(struct sc_security_env));
memcpy((sc_security_env_t *) env, &tmp, sizeof(struct sc_security_env));
}

sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xC1, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/libopensc/card-oberthur.c
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,7 @@ auth_pin_change(struct sc_card *card, unsigned int type,
struct sc_pin_cmd_data *data, int *tries_left)
{
struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
int rv;
int rv = SC_ERROR_INTERNAL;

SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);

Expand Down Expand Up @@ -1905,7 +1905,7 @@ auth_pin_reset(struct sc_card *card, unsigned int type,
static int
auth_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data, int *tries_left)
{
int rv;
int rv = SC_ERROR_INTERNAL;

SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
if (data->pin_type != SC_AC_CHV)
Expand Down
4 changes: 2 additions & 2 deletions src/libopensc/card-openpgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ pgp_new_blob(sc_card_t *card, struct blob *parent, unsigned int file_id,
/* FIXME sc_format_path expects an hex string of an file
* identifier. ushort2bebytes instead delivers a two bytes binary
* string */
sc_format_path(ushort2bebytes(id_str, file_id), &blob->file->path);
sc_format_path((char *) ushort2bebytes(id_str, file_id), &blob->file->path);
}

/* find matching DO info: set file type depending on it */
Expand Down Expand Up @@ -1687,7 +1687,7 @@ pgp_parse_and_set_pubkey_output(sc_card_t *card, u8* data, size_t data_len,
LOG_TEST_RET(card->ctx, r, "Cannot store creation time");

/* Parse response. Ref: pgp_enumerate_blob() */
while (data_len > (in - data)) {
while (data_len > (size_t) (in - data)) {
unsigned int cla, tag, tmptag;
size_t len;
u8 *part = in;
Expand Down
2 changes: 1 addition & 1 deletion src/libopensc/card-piv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ static int piv_compute_signature(sc_card_t *card,
piv_private_data_t * priv = PIV_DATA(card);
int r;
int i;
int nLen;
size_t nLen;
u8 rbuf[128]; /* For EC conversions 384 will fit */
size_t rbuflen = sizeof(rbuf);
const u8 * body;
Expand Down
2 changes: 1 addition & 1 deletion src/libopensc/pkcs15-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sc_pkcs15_read_data_object(struct sc_pkcs15_card *p15card,
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);

if (!info->data.value) {
r = sc_pkcs15_read_file(p15card, &info->path, &info->data.value, &info->data.len);
r = sc_pkcs15_read_file(p15card, &info->path, (unsigned char **) &info->data.value, (size_t *) &info->data.len);
LOG_TEST_RET(ctx, r, "Cannot get DATA object data");
}

Expand Down
6 changes: 3 additions & 3 deletions src/libopensc/pkcs15-piv.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ static int piv_get_guid(struct sc_pkcs15_card *p15card, const struct sc_pkcs15_o
struct sc_serial_number serialnr;
struct sc_pkcs15_id id;
unsigned char guid_bin[SC_PKCS15_MAX_ID_SIZE + SC_MAX_SERIALNR];
size_t bin_size, offs, tlen;
int r, i;
size_t bin_size, offs, tlen, i;
int r;
unsigned char fbit, fbits, fbyte, fbyte2, fnibble;
unsigned char *f5p, *f8p;

Expand Down Expand Up @@ -219,7 +219,7 @@ static int piv_get_guid(struct sc_pkcs15_card *p15card, const struct sc_pkcs15_o
offs = tlen - bin_size;

for (i=0; i<bin_size; i++)
sprintf(out + i*2, "%02x", guid_bin[offs + i]);
sprintf((char *) out + i*2, "%02x", guid_bin[offs + i]);

return SC_SUCCESS;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libopensc/pkcs15-sec.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int sc_pkcs15_decipher(struct sc_pkcs15_card *p15card,
{
sc_context_t *ctx = p15card->card->ctx;
int r;
sc_algorithm_info_t *alg_info;
sc_algorithm_info_t *alg_info = NULL;
sc_security_env_t senv;
const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
unsigned long pad_flags = 0, sec_flags = 0;
Expand Down Expand Up @@ -190,7 +190,7 @@ int sc_pkcs15_derive(struct sc_pkcs15_card *p15card,
{
sc_context_t *ctx = p15card->card->ctx;
int r;
sc_algorithm_info_t *alg_info;
sc_algorithm_info_t *alg_info = NULL;
sc_security_env_t senv;
const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
unsigned long pad_flags = 0, sec_flags = 0;
Expand Down
9 changes: 6 additions & 3 deletions src/libopensc/pkcs15.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#include <openssl/sha.h>
#endif

#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif

static const struct sc_asn1_entry c_asn1_twlabel[] = {
{ "twlabel", SC_ASN1_UTF8STRING, SC_ASN1_TAG_UTF8STRING, 0, NULL, NULL },
{ NULL, 0, 0, 0, NULL, NULL }
Expand Down Expand Up @@ -1261,7 +1265,6 @@ __sc_pkcs15_search_objects(struct sc_pkcs15_card *p15card, unsigned int class_ma
struct sc_pkcs15_df *df = NULL;
unsigned int df_mask = 0;
size_t match_count = 0;
int r = 0;

if (type)
class_mask |= SC_PKCS15_TYPE_TO_CLASS(type);
Expand Down Expand Up @@ -1300,7 +1303,8 @@ __sc_pkcs15_search_objects(struct sc_pkcs15_card *p15card, unsigned int class_ma
continue;
/* Enumerate the DF's, so p15card->obj_list is
* populated. */
r = sc_pkcs15_parse_df(p15card, df);
/* FIXME dont ignore errors */
sc_pkcs15_parse_df(p15card, df);
}

/* And now loop over all objects */
Expand Down Expand Up @@ -2533,7 +2537,6 @@ sc_pkcs15_get_supported_algo(struct sc_pkcs15_card *p15card, unsigned operation,
return info;
}


int
sc_pkcs15_get_generalized_time(struct sc_context *ctx, char **out)
{
Expand Down
2 changes: 1 addition & 1 deletion src/libopensc/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ typedef struct sc_apdu {
int cse; /* APDU case */
unsigned char cla, ins, p1, p2; /* CLA, INS, P1 and P2 bytes */
size_t lc, le; /* Lc and Le bytes */
unsigned char *data; /* S-APDU data */
const unsigned char *data; /* S-APDU data */
size_t datalen; /* length of data in S-APDU */
unsigned char *resp; /* R-APDU data buffer */
size_t resplen; /* in: size of R-APDU buffer,
Expand Down
2 changes: 0 additions & 2 deletions src/pkcs11/framework-pkcs15.c
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,6 @@ pkcs15_create_private_key(struct sc_pkcs11_slot *slot, struct sc_profile *profil
struct sc_pkcs15_auth_info *pin = NULL;
CK_KEY_TYPE key_type;
struct sc_pkcs15_prkey_rsa *rsa = NULL;
struct sc_pkcs15_prkey_ec *ec = NULL;
struct sc_pkcs15_prkey_gostr3410 *gost = NULL;
int rc, rv;
char label[SC_PKCS15_MAX_LABEL_SIZE];
Expand Down Expand Up @@ -1969,7 +1968,6 @@ pkcs15_create_private_key(struct sc_pkcs11_slot *slot, struct sc_profile *profil
break;
case CKK_EC:
args.key.algorithm = SC_ALGORITHM_EC;
ec = &args.key.u.ec;
/* TODO: -DEE Do not have PKCS15 card with EC to test this */
/* fall through */
default:
Expand Down
2 changes: 1 addition & 1 deletion src/pkcs11/pkcs11-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ CK_RV C_InitPIN(CK_SESSION_HANDLE hSession, CK_CHAR_PTR pPin, CK_ULONG ulPinLen)
struct sc_pkcs11_session *session;
struct sc_pkcs11_slot *slot;

sc_log(context, "C_InitPIN() called, pin '%s'", pPin ? pPin : "<null>");
sc_log(context, "C_InitPIN() called, pin '%s'", pPin ? (char *) pPin : "<null>");
if (pPin == NULL_PTR && ulPinLen > 0)
return CKR_ARGUMENTS_BAD;

Expand Down
Loading

0 comments on commit 0b567db

Please sign in to comment.