treat records with size_t

This commit is contained in:
Frank Morgner 2019-01-14 10:35:00 +01:00
parent 1106508656
commit 3fe198f21e
5 changed files with 23 additions and 22 deletions

View File

@ -400,7 +400,7 @@ static int process_fcp_v3_4(sc_context_t *ctx, sc_file_t *file,
file->record_length = (tag[2] << 8) + tag[3]; file->record_length = (tag[2] << 8) + tag[3];
file->record_count = tag[4]; file->record_count = tag[4];
sc_log(ctx, sc_log(ctx,
" rec_len: %d rec_cnt: %d\n\n", " rec_len: %"SC_FORMAT_LEN_SIZE_T"u rec_cnt: %"SC_FORMAT_LEN_SIZE_T"u\n\n",
file->record_length, file->record_count); file->record_length, file->record_count);
} }
} }

View File

@ -237,8 +237,8 @@ typedef struct sc_file {
int sid; /* short EF identifier (1 byte) */ int sid; /* short EF identifier (1 byte) */
struct sc_acl_entry *acl[SC_MAX_AC_OPS]; /* Access Control List */ struct sc_acl_entry *acl[SC_MAX_AC_OPS]; /* Access Control List */
int record_length; /* In case of fixed-length or cyclic EF */ size_t record_length; /* In case of fixed-length or cyclic EF */
int record_count; /* Valid, if not transparent EF or DF */ size_t record_count; /* Valid, if not transparent EF or DF */
unsigned char *sec_attr; /* security data in proprietary format. tag '86' */ unsigned char *sec_attr; /* security data in proprietary format. tag '86' */
size_t sec_attr_len; size_t sec_attr_len;

View File

@ -171,7 +171,7 @@ awp_new_file(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
} }
sc_log(ctx, sc_log(ctx,
"info_file(id:%04X,size:%"SC_FORMAT_LEN_SIZE_T"u,rlen:%i)", "info_file(id:%04X,size:%"SC_FORMAT_LEN_SIZE_T"u,rlen:%"SC_FORMAT_LEN_SIZE_T"u)",
ifile->id, ifile->size, ifile->record_length); ifile->id, ifile->size, ifile->record_length);
*info_out = ifile; *info_out = ifile;
} }
@ -236,7 +236,7 @@ awp_update_blob(struct sc_context *ctx,
static int static int
awp_new_container_entry(struct sc_pkcs15_card *p15card, unsigned char *buff, int len) awp_new_container_entry(struct sc_pkcs15_card *p15card, unsigned char *buff, size_t len)
{ {
struct sc_context *ctx = p15card->card->ctx; struct sc_context *ctx = p15card->card->ctx;
int mm, rv = 0; int mm, rv = 0;
@ -274,7 +274,7 @@ awp_create_container_record (struct sc_pkcs15_card *p15card, struct sc_profile *
unsigned char *buff = NULL; unsigned char *buff = NULL;
LOG_FUNC_CALLED(ctx); LOG_FUNC_CALLED(ctx);
sc_log(ctx, "container file(file-id:%X,rlen:%i,rcount:%i)", sc_log(ctx, "container file(file-id:%X,rlen:%"SC_FORMAT_LEN_SIZE_T"u,rcount:%"SC_FORMAT_LEN_SIZE_T"u)",
list_file->id, list_file->record_length, list_file->record_count); list_file->id, list_file->record_length, list_file->record_count);
buff = malloc(list_file->record_length); buff = malloc(list_file->record_length);
@ -322,14 +322,14 @@ awp_create_container(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
rv = awp_new_file(p15card, profile, COSM_CONTAINER_LIST, 0, &clist, NULL); rv = awp_new_file(p15card, profile, COSM_CONTAINER_LIST, 0, &clist, NULL);
LOG_TEST_RET(ctx, rv, "Create container failed"); LOG_TEST_RET(ctx, rv, "Create container failed");
sc_log(ctx, "contaner cfile(rcount:%i,rlength:%i)", clist->record_count, clist->record_length); sc_log(ctx, "contaner cfile(rcount:%"SC_FORMAT_LEN_SIZE_T"u,rlength:%"SC_FORMAT_LEN_SIZE_T"u)", clist->record_count, clist->record_length);
rv = sc_select_file(p15card->card, &clist->path, &file); rv = sc_select_file(p15card->card, &clist->path, &file);
LOG_TEST_RET(ctx, rv, "Create container failed: cannot select container's list"); LOG_TEST_RET(ctx, rv, "Create container failed: cannot select container's list");
file->record_length = clist->record_length; file->record_length = clist->record_length;
sc_log(ctx, "contaner file(rcount:%i,rlength:%i)", file->record_count, file->record_length); sc_log(ctx, "contaner file(rcount:%"SC_FORMAT_LEN_SIZE_T"u,rlength:%"SC_FORMAT_LEN_SIZE_T"u)", file->record_count, file->record_length);
sc_log(ctx, "Append new record %i for private key", file->record_count + 1); sc_log(ctx, "Append new record %"SC_FORMAT_LEN_SIZE_T"u for private key", file->record_count + 1);
rv = awp_create_container_record(p15card, profile, file, acc); rv = awp_create_container_record(p15card, profile, file, acc);
@ -343,7 +343,7 @@ awp_create_container(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
static int static int
awp_update_container_entry (struct sc_pkcs15_card *p15card, struct sc_profile *profile, awp_update_container_entry (struct sc_pkcs15_card *p15card, struct sc_profile *profile,
struct sc_file *list_file, int type, int file_id, struct sc_file *list_file, int type, int file_id,
int rec, int offs) size_t rec, int offs)
{ {
struct sc_context *ctx = p15card->card->ctx; struct sc_context *ctx = p15card->card->ctx;
int rv; int rv;
@ -351,9 +351,9 @@ awp_update_container_entry (struct sc_pkcs15_card *p15card, struct sc_profile *p
LOG_FUNC_CALLED(ctx); LOG_FUNC_CALLED(ctx);
sc_log(ctx, sc_log(ctx,
"update container entry(type:%X,id %i,rec %i,offs %i", "update container entry(type:%X,id %i,rec %"SC_FORMAT_LEN_SIZE_T"u,offs %i",
type, file_id, rec, offs); type, file_id, rec, offs);
sc_log(ctx, "container file(file-id:%X,rlen:%i,rcount:%i)", sc_log(ctx, "container file(file-id:%X,rlen:%"SC_FORMAT_LEN_SIZE_T"u,rcount:%"SC_FORMAT_LEN_SIZE_T"u)",
list_file->id, list_file->record_length, list_file->record_count); list_file->id, list_file->record_length, list_file->record_count);
buff = malloc(list_file->record_length); buff = malloc(list_file->record_length);
@ -427,7 +427,8 @@ awp_update_container(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
struct sc_context *ctx = p15card->card->ctx; struct sc_context *ctx = p15card->card->ctx;
struct sc_file *clist = NULL, *file = NULL; struct sc_file *clist = NULL, *file = NULL;
struct sc_path private_path; struct sc_path private_path;
int rv = 0, rec, rec_offs; int rv = 0;
size_t rec, rec_offs;
unsigned char *list = NULL; unsigned char *list = NULL;
LOG_FUNC_CALLED(ctx); LOG_FUNC_CALLED(ctx);
@ -484,7 +485,7 @@ awp_update_container(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
for (rec_offs=0; !rv && rec_offs<12; rec_offs+=6) { for (rec_offs=0; !rv && rec_offs<12; rec_offs+=6) {
int offs; int offs;
sc_log(ctx, "rec %i; rec_offs %i", rec, rec_offs); sc_log(ctx, "rec %"SC_FORMAT_LEN_SIZE_T"u; rec_offs %"SC_FORMAT_LEN_SIZE_T"u", rec, rec_offs);
offs = rec*AWP_CONTAINER_RECORD_LEN + rec_offs; offs = rec*AWP_CONTAINER_RECORD_LEN + rec_offs;
if (*(list + offs + 2)) { if (*(list + offs + 2)) {
unsigned char *buff = NULL; unsigned char *buff = NULL;

View File

@ -1514,7 +1514,7 @@ static int do_update_record(int argc, char **argv)
u8 buf[240]; u8 buf[240];
size_t buflen; size_t buflen;
int r, i, err = 1; int r, i, err = 1;
int rec, offs; size_t rec, offs;
sc_path_t path; sc_path_t path;
sc_file_t *file; sc_file_t *file;
@ -1525,7 +1525,7 @@ static int do_update_record(int argc, char **argv)
rec = strtol(argv[1],NULL,10); rec = strtol(argv[1],NULL,10);
offs = strtol(argv[2],NULL,10); offs = strtol(argv[2],NULL,10);
printf("in: %i; %i; %s\n", rec, offs, argv[3]); printf("in: %"SC_FORMAT_LEN_SIZE_T"u; %"SC_FORMAT_LEN_SIZE_T"u; %s\n", rec, offs, argv[3]);
r = sc_lock(card); r = sc_lock(card);
if (r == SC_SUCCESS) if (r == SC_SUCCESS)
@ -1540,13 +1540,13 @@ static int do_update_record(int argc, char **argv)
fprintf(stderr, "EF structure should be SC_FILE_EF_LINEAR_VARIABLE\n"); fprintf(stderr, "EF structure should be SC_FILE_EF_LINEAR_VARIABLE\n");
goto err; goto err;
} else if (rec < 1 || rec > file->record_count) { } else if (rec < 1 || rec > file->record_count) {
fprintf(stderr, "Invalid record number %i\n", rec); fprintf(stderr, "Invalid record number %"SC_FORMAT_LEN_SIZE_T"u\n", rec);
goto err; goto err;
} }
r = sc_read_record(card, rec, buf, sizeof(buf), SC_RECORD_BY_REC_NR); r = sc_read_record(card, rec, buf, sizeof(buf), SC_RECORD_BY_REC_NR);
if (r<0) { if (r<0) {
fprintf(stderr, "Cannot read record %i; return %i\n", rec, r); fprintf(stderr, "Cannot read record %"SC_FORMAT_LEN_SIZE_T"u; return %i\n", rec, r);
goto err;; goto err;;
} }
@ -1562,11 +1562,11 @@ static int do_update_record(int argc, char **argv)
r = sc_update_record(card, rec, buf, r, SC_RECORD_BY_REC_NR); r = sc_update_record(card, rec, buf, r, SC_RECORD_BY_REC_NR);
sc_unlock(card); sc_unlock(card);
if (r<0) { if (r<0) {
fprintf(stderr, "Cannot update record %i; return %i\n", rec, r); fprintf(stderr, "Cannot update record %"SC_FORMAT_LEN_SIZE_T"u; return %i\n", rec, r);
goto err; goto err;
} }
printf("Total of %d bytes written to record %i at %i offset.\n", printf("Total of %d bytes written to record %"SC_FORMAT_LEN_SIZE_T"u at %"SC_FORMAT_LEN_SIZE_T"u offset.\n",
i, rec, offs); i, rec, offs);
err = 0; err = 0;

View File

@ -438,10 +438,10 @@ static int print_file(sc_card_t *in_card, const sc_file_t *file,
free(buf); free(buf);
} else { } else {
unsigned char buf[256]; unsigned char buf[256];
int i; size_t i;
for (i=0; i < file->record_count; i++) { for (i=0; i < file->record_count; i++) {
printf("Record %d\n", i); printf("Record %"SC_FORMAT_LEN_SIZE_T"u\n", i);
r = sc_lock(card); r = sc_lock(card);
if (r == SC_SUCCESS) if (r == SC_SUCCESS)
r = sc_read_record(in_card, i, buf, 256, 0); r = sc_read_record(in_card, i, buf, 256, 0);