fixed errors reported by cppcheck: part 1
partially applied the pull request #182 from Frank Morgner -- updated the common frameworks source files
This commit is contained in:
parent
2dee7baae0
commit
f641ebd248
|
@ -36,8 +36,10 @@ C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs)
|
||||||
mod = calloc(1, sizeof(*mod));
|
mod = calloc(1, sizeof(*mod));
|
||||||
mod->_magic = MAGIC;
|
mod->_magic = MAGIC;
|
||||||
|
|
||||||
if (mspec == NULL)
|
if (mspec == NULL) {
|
||||||
|
free(mod);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
mod->handle = sc_dlopen(mspec);
|
mod->handle = sc_dlopen(mspec);
|
||||||
if (mod->handle == NULL) {
|
if (mod->handle == NULL) {
|
||||||
fprintf(stderr, "sc_dlopen failed: %s\n", sc_dlerror());
|
fprintf(stderr, "sc_dlopen failed: %s\n", sc_dlerror());
|
||||||
|
|
|
@ -178,6 +178,7 @@ static inline struct list_entry_s *list_findpos(const list_t *restrict l, int po
|
||||||
#define READ_ERRCHECK(fd, msgbuf, msglen) do { \
|
#define READ_ERRCHECK(fd, msgbuf, msglen) do { \
|
||||||
if (read(fd, msgbuf, msglen) != msglen) { \
|
if (read(fd, msgbuf, msglen) != msglen) { \
|
||||||
/*errno = EPROTO;*/ \
|
/*errno = EPROTO;*/ \
|
||||||
|
free(buf); \
|
||||||
return -1; \
|
return -1; \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
@ -1199,7 +1200,7 @@ int list_dump_filedescriptor(const list_t *restrict l, int fd, size_t *restrict
|
||||||
int list_restore_filedescriptor(list_t *restrict l, int fd, size_t *restrict len) {
|
int list_restore_filedescriptor(list_t *restrict l, int fd, size_t *restrict len) {
|
||||||
struct list_dump_header_s header;
|
struct list_dump_header_s header;
|
||||||
unsigned long cnt;
|
unsigned long cnt;
|
||||||
void *buf;
|
void *buf = NULL;
|
||||||
uint32_t elsize, totreadlen, totmemorylen;
|
uint32_t elsize, totreadlen, totmemorylen;
|
||||||
|
|
||||||
memset(& header, 0, sizeof(header));
|
memset(& header, 0, sizeof(header));
|
||||||
|
|
|
@ -209,7 +209,8 @@ static void sc_asn1_print_object_id(const u8 * buf, size_t buflen)
|
||||||
{
|
{
|
||||||
struct sc_object_id oid;
|
struct sc_object_id oid;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char sbuf[256];
|
char tmp[12];
|
||||||
|
char sbuf[(sizeof tmp)*SC_MAX_OBJECT_ID_OCTETS];
|
||||||
|
|
||||||
if (sc_asn1_decode_object_id(buf, buflen, &oid)) {
|
if (sc_asn1_decode_object_id(buf, buflen, &oid)) {
|
||||||
printf("decode error");
|
printf("decode error");
|
||||||
|
@ -218,7 +219,6 @@ static void sc_asn1_print_object_id(const u8 * buf, size_t buflen)
|
||||||
|
|
||||||
sbuf[0] = 0;
|
sbuf[0] = 0;
|
||||||
for (i = 0; (i < SC_MAX_OBJECT_ID_OCTETS) && (oid.value[i] != -1); i++) {
|
for (i = 0; (i < SC_MAX_OBJECT_ID_OCTETS) && (oid.value[i] != -1); i++) {
|
||||||
char tmp[12];
|
|
||||||
|
|
||||||
if (i)
|
if (i)
|
||||||
strcat(sbuf, ".");
|
strcat(sbuf, ".");
|
||||||
|
@ -1016,7 +1016,7 @@ static int asn1_encode_se_info(sc_context_t *ctx,
|
||||||
struct sc_pkcs15_sec_env_info **se, size_t se_num,
|
struct sc_pkcs15_sec_env_info **se, size_t se_num,
|
||||||
unsigned char **buf, size_t *bufsize, int depth)
|
unsigned char **buf, size_t *bufsize, int depth)
|
||||||
{
|
{
|
||||||
unsigned char *ptr = NULL, *out = NULL;
|
unsigned char *ptr = NULL, *out = NULL, *p;
|
||||||
size_t ptrlen = 0, outlen = 0, idx;
|
size_t ptrlen = 0, outlen = 0, idx;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -1038,11 +1038,12 @@ static int asn1_encode_se_info(sc_context_t *ctx,
|
||||||
if (ret != SC_SUCCESS)
|
if (ret != SC_SUCCESS)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
out = (unsigned char *) realloc(out, outlen + ptrlen);
|
p = (unsigned char *) realloc(out, outlen + ptrlen);
|
||||||
if (!out) {
|
if (!p) {
|
||||||
ret = SC_ERROR_OUT_OF_MEMORY;
|
ret = SC_ERROR_OUT_OF_MEMORY;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
out = p;
|
||||||
memcpy(out + outlen, ptr, ptrlen);
|
memcpy(out + outlen, ptr, ptrlen);
|
||||||
outlen += ptrlen;
|
outlen += ptrlen;
|
||||||
free(ptr);
|
free(ptr);
|
||||||
|
|
|
@ -281,14 +281,18 @@ asn1_decode_ec_params(sc_context_t *ctx, void **paramp,
|
||||||
sc_format_asn1_entry(asn1_ec_params + 1, &curve, 0, 0);
|
sc_format_asn1_entry(asn1_ec_params + 1, &curve, 0, 0);
|
||||||
|
|
||||||
/* Some signature algorithms will not have any data */
|
/* Some signature algorithms will not have any data */
|
||||||
if (buflen == 0 || buf == NULL )
|
if (buflen == 0 || buf == NULL) {
|
||||||
|
free(ecp);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
r = sc_asn1_decode_choice(ctx, asn1_ec_params, buf, buflen, NULL, NULL);
|
r = sc_asn1_decode_choice(ctx, asn1_ec_params, buf, buflen, NULL, NULL);
|
||||||
/* r = index into asn1_ec_params */
|
/* r = index into asn1_ec_params */
|
||||||
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DEE - asn1_decode_ec_params r=%d", r);
|
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DEE - asn1_decode_ec_params r=%d", r);
|
||||||
if (r < 0)
|
if (r < 0) {
|
||||||
|
free(ecp);
|
||||||
return r;
|
return r;
|
||||||
|
}
|
||||||
if (r <= 1) {
|
if (r <= 1) {
|
||||||
ecp->der = malloc(buflen);
|
ecp->der = malloc(buflen);
|
||||||
|
|
||||||
|
@ -297,7 +301,7 @@ sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DEE - asn1_decode_ec_params r=%d", r);
|
||||||
|
|
||||||
ecp->der_len = buflen;
|
ecp->der_len = buflen;
|
||||||
|
|
||||||
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DEE - asn1_decode_ec_params paramp=%p %p:%d %d",
|
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DEE - asn1_decode_ec_params paramp=%p %p:%d %d",
|
||||||
ecp, ecp->der, ecp->der_len, ecp->type);
|
ecp, ecp->der, ecp->der_len, ecp->type);
|
||||||
memcpy(ecp->der, buf, buflen); /* copy der parameters */
|
memcpy(ecp->der, buf, buflen); /* copy der parameters */
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -1854,7 +1854,7 @@ int sc_pkcs15_encode_df(sc_context_t *ctx,
|
||||||
struct sc_pkcs15_df *df,
|
struct sc_pkcs15_df *df,
|
||||||
u8 **buf_out, size_t *bufsize_out)
|
u8 **buf_out, size_t *bufsize_out)
|
||||||
{
|
{
|
||||||
u8 *buf = NULL, *tmp = NULL;
|
u8 *buf = NULL, *tmp = NULL, *p;
|
||||||
size_t bufsize = 0, tmpsize;
|
size_t bufsize = 0, tmpsize;
|
||||||
const struct sc_pkcs15_object *obj;
|
const struct sc_pkcs15_object *obj;
|
||||||
int (* func)(sc_context_t *, const struct sc_pkcs15_object *nobj,
|
int (* func)(sc_context_t *, const struct sc_pkcs15_object *nobj,
|
||||||
|
@ -1897,7 +1897,13 @@ int sc_pkcs15_encode_df(sc_context_t *ctx,
|
||||||
free(buf);
|
free(buf);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
buf = (u8 *) realloc(buf, bufsize + tmpsize);
|
p = (u8 *) realloc(buf, bufsize + tmpsize);
|
||||||
|
if (!p) {
|
||||||
|
free(tmp);
|
||||||
|
free(buf);
|
||||||
|
return SC_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
buf = p;
|
||||||
memcpy(buf + bufsize, tmp, tmpsize);
|
memcpy(buf + bufsize, tmp, tmpsize);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
bufsize += tmpsize;
|
bufsize += tmpsize;
|
||||||
|
|
|
@ -386,8 +386,11 @@ static int ctapi_load_module(sc_context_t *ctx,
|
||||||
|
|
||||||
reader = calloc(1, sizeof(sc_reader_t));
|
reader = calloc(1, sizeof(sc_reader_t));
|
||||||
priv = calloc(1, sizeof(struct ctapi_private_data));
|
priv = calloc(1, sizeof(struct ctapi_private_data));
|
||||||
if (!priv)
|
if (!priv || !reader) {
|
||||||
|
free(reader);
|
||||||
|
free(priv);
|
||||||
return SC_ERROR_OUT_OF_MEMORY;
|
return SC_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
reader->drv_data = priv;
|
reader->drv_data = priv;
|
||||||
reader->ops = &ctapi_ops;
|
reader->ops = &ctapi_ops;
|
||||||
reader->driver = &ctapi_drv;
|
reader->driver = &ctapi_drv;
|
||||||
|
|
|
@ -774,7 +774,7 @@ static DWORD
|
||||||
md_pkcs15_encode_cmapfile(PCARD_DATA pCardData, unsigned char **out, size_t *out_len)
|
md_pkcs15_encode_cmapfile(PCARD_DATA pCardData, unsigned char **out, size_t *out_len)
|
||||||
{
|
{
|
||||||
VENDOR_SPECIFIC *vs;
|
VENDOR_SPECIFIC *vs;
|
||||||
unsigned char *encoded, *ret;
|
unsigned char *encoded, *ret, *p;
|
||||||
size_t guid_len, encoded_len, flags_len, ret_len;
|
size_t guid_len, encoded_len, flags_len, ret_len;
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
|
@ -814,11 +814,13 @@ md_pkcs15_encode_cmapfile(PCARD_DATA pCardData, unsigned char **out, size_t *out
|
||||||
return SCARD_F_INTERNAL_ERROR;
|
return SCARD_F_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = realloc(ret, ret_len + encoded_len);
|
p = realloc(ret, ret_len + encoded_len);
|
||||||
if (!ret) {
|
if (!p) {
|
||||||
logprintf(pCardData, 3, "MdEncodeCMapFile(): realloc failed\n");
|
logprintf(pCardData, 3, "MdEncodeCMapFile(): realloc failed\n");
|
||||||
|
free(ret);
|
||||||
return SCARD_E_NO_MEMORY;
|
return SCARD_E_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
ret = p;
|
||||||
memcpy(ret + ret_len, encoded, encoded_len);
|
memcpy(ret + ret_len, encoded, encoded_len);
|
||||||
free(encoded);
|
free(encoded);
|
||||||
ret_len += encoded_len;
|
ret_len += encoded_len;
|
||||||
|
|
|
@ -2082,6 +2082,7 @@ pkcs15_create_secret_key(struct sc_pkcs11_slot *slot, struct sc_profile *profile
|
||||||
rv = CKR_OK;
|
rv = CKR_OK;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
free(key_obj);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1520,8 +1520,10 @@ sc_pkcs15init_store_public_key(struct sc_pkcs15_card *p15card,
|
||||||
/* FIXME: malloc() call in pkcs15init, but free() call
|
/* FIXME: malloc() call in pkcs15init, but free() call
|
||||||
* in libopensc (sc_pkcs15_free_prkey_info) */
|
* in libopensc (sc_pkcs15_free_prkey_info) */
|
||||||
key_info->params.data = malloc(key_info->params.len);
|
key_info->params.data = malloc(key_info->params.len);
|
||||||
if (!key_info->params.data)
|
if (!key_info->params.data) {
|
||||||
|
/* FIXME free object with sc_pkcs15init_delete_object */
|
||||||
return SC_ERROR_OUT_OF_MEMORY;
|
return SC_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
keyinfo_gostparams = key_info->params.data;
|
keyinfo_gostparams = key_info->params.data;
|
||||||
keyinfo_gostparams->gostr3410 = keyargs->params.gost.gostr3410;
|
keyinfo_gostparams->gostr3410 = keyargs->params.gost.gostr3410;
|
||||||
keyinfo_gostparams->gostr3411 = keyargs->params.gost.gostr3411;
|
keyinfo_gostparams->gostr3411 = keyargs->params.gost.gostr3411;
|
||||||
|
|
|
@ -97,7 +97,12 @@ scconf_block **scconf_find_blocks(const scconf_context * config, const scconf_bl
|
||||||
}
|
}
|
||||||
size = 0;
|
size = 0;
|
||||||
alloc_size = 10;
|
alloc_size = 10;
|
||||||
blocks = (scconf_block **) realloc(blocks, sizeof(scconf_block *) * alloc_size);
|
tmp = (scconf_block **) realloc(blocks, sizeof(scconf_block *) * alloc_size);
|
||||||
|
if (!tmp) {
|
||||||
|
free(blocks);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
blocks = tmp;
|
||||||
|
|
||||||
for (item = block->items; item; item = item->next) {
|
for (item = block->items; item; item = item->next) {
|
||||||
if (item->type == SCCONF_ITEM_TYPE_BLOCK &&
|
if (item->type == SCCONF_ITEM_TYPE_BLOCK &&
|
||||||
|
|
|
@ -83,10 +83,12 @@ static char *scconf_list_get_string(scconf_list * list)
|
||||||
}
|
}
|
||||||
len = 0;
|
len = 0;
|
||||||
alloc_len = 1024;
|
alloc_len = 1024;
|
||||||
buffer = (char *) realloc(buffer, alloc_len);
|
tmp = (char *) realloc(buffer, alloc_len);
|
||||||
if (!buffer) {
|
if (!tmp) {
|
||||||
|
free(buffer);
|
||||||
return strdup("");
|
return strdup("");
|
||||||
}
|
}
|
||||||
|
buffer = tmp;
|
||||||
memset(buffer, 0, alloc_len);
|
memset(buffer, 0, alloc_len);
|
||||||
while (list) {
|
while (list) {
|
||||||
datalen = strlen(list->data);
|
datalen = strlen(list->data);
|
||||||
|
|
|
@ -7,34 +7,37 @@
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int len;
|
int len, r = 1;
|
||||||
FILE *inf;
|
FILE *inf = NULL;
|
||||||
u8 buf[8192];
|
u8 buf[8192];
|
||||||
u8 outbuf[8192];
|
u8 outbuf[8192];
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
fprintf(stderr, "Usage: base64 <file>\n");
|
fprintf(stderr, "Usage: base64 <file>\n");
|
||||||
return 1;
|
goto err;
|
||||||
}
|
}
|
||||||
inf = fopen(argv[1], "r");
|
inf = fopen(argv[1], "r");
|
||||||
if (inf == NULL) {
|
if (inf == NULL) {
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
return 1;
|
goto err;
|
||||||
}
|
}
|
||||||
len = fread(buf, 1, sizeof(buf), inf);
|
len = fread(buf, 1, sizeof(buf), inf);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
perror("fread");
|
perror("fread");
|
||||||
return 1;
|
goto err;
|
||||||
}
|
}
|
||||||
if (len == 8192) {
|
if (len == 8192) {
|
||||||
fprintf(stderr, "Too long input file.\n");
|
fprintf(stderr, "Too long input file.\n");
|
||||||
return 1;
|
goto err;
|
||||||
}
|
}
|
||||||
len = sc_base64_decode((const char *) buf, outbuf, sizeof(outbuf));
|
len = sc_base64_decode((const char *) buf, outbuf, sizeof(outbuf));
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
fprintf(stderr, "Base64 decoding failed: %s\n", sc_strerror(len));
|
fprintf(stderr, "Base64 decoding failed: %s\n", sc_strerror(len));
|
||||||
return 1;
|
goto err;
|
||||||
}
|
}
|
||||||
fwrite(outbuf, len, 1, stdout);
|
fwrite(outbuf, len, 1, stdout);
|
||||||
return 0;
|
r = 0;
|
||||||
|
err:
|
||||||
|
fclose(inf);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -656,6 +656,7 @@ int main(int argc, char * const argv[])
|
||||||
int action_count = 0;
|
int action_count = 0;
|
||||||
const char *opt_driver = NULL;
|
const char *opt_driver = NULL;
|
||||||
const char *opt_conf_entry = NULL;
|
const char *opt_conf_entry = NULL;
|
||||||
|
char **p;
|
||||||
sc_context_param_t ctx_param;
|
sc_context_param_t ctx_param;
|
||||||
|
|
||||||
setbuf(stderr, NULL);
|
setbuf(stderr, NULL);
|
||||||
|
@ -695,8 +696,14 @@ int main(int argc, char * const argv[])
|
||||||
action_count++;
|
action_count++;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
opt_apdus = (char **) realloc(opt_apdus,
|
p = (char **) realloc(opt_apdus,
|
||||||
(opt_apdu_count + 1) * sizeof(char *));
|
(opt_apdu_count + 1) * sizeof(char *));
|
||||||
|
if (!p) {
|
||||||
|
fprintf(stderr, "Not enough memory\n");
|
||||||
|
err = 1;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
opt_apdus = p;
|
||||||
opt_apdus[opt_apdu_count] = optarg;
|
opt_apdus[opt_apdu_count] = optarg;
|
||||||
do_send_apdu++;
|
do_send_apdu++;
|
||||||
if (opt_apdu_count == 0)
|
if (opt_apdu_count == 0)
|
||||||
|
|
|
@ -1342,6 +1342,7 @@ static int unblock_pin(void)
|
||||||
if (puk == NULL && verbose)
|
if (puk == NULL && verbose)
|
||||||
printf("PUK value will be prompted with pinpad.\n");
|
printf("PUK value will be prompted with pinpad.\n");
|
||||||
|
|
||||||
|
/* FIXME should OPENSSL_cleanse on pin/puk data */
|
||||||
pin = opt_pin ? opt_pin : opt_newpin;
|
pin = opt_pin ? opt_pin : opt_newpin;
|
||||||
while (pin == NULL) {
|
while (pin == NULL) {
|
||||||
u8 *pin2;
|
u8 *pin2;
|
||||||
|
@ -1369,6 +1370,7 @@ static int unblock_pin(void)
|
||||||
r = sc_pkcs15_unblock_pin(p15card, pin_obj,
|
r = sc_pkcs15_unblock_pin(p15card, pin_obj,
|
||||||
puk, puk ? strlen((char *) puk) : 0,
|
puk, puk ? strlen((char *) puk) : 0,
|
||||||
pin, pin ? strlen((char *) pin) : 0);
|
pin, pin ? strlen((char *) pin) : 0);
|
||||||
|
/* FIXME must free the puk somewhere */
|
||||||
if (r == SC_ERROR_PIN_CODE_INCORRECT) {
|
if (r == SC_ERROR_PIN_CODE_INCORRECT) {
|
||||||
fprintf(stderr, "PUK code incorrect; tries left: %d\n", pinfo->tries_left);
|
fprintf(stderr, "PUK code incorrect; tries left: %d\n", pinfo->tries_left);
|
||||||
return 3;
|
return 3;
|
||||||
|
@ -1462,6 +1464,7 @@ static int change_pin(void)
|
||||||
}
|
}
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("PIN code changed successfully.\n");
|
printf("PIN code changed successfully.\n");
|
||||||
|
/* FIXME must free the pincode somewhere */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ void util_print_usage_and_die(const char *app_name, const struct option options[
|
||||||
|
|
||||||
const char * util_acl_to_str(const sc_acl_entry_t *e)
|
const char * util_acl_to_str(const sc_acl_entry_t *e)
|
||||||
{
|
{
|
||||||
static char line[80], buf[10];
|
static char line[80], buf[20];
|
||||||
unsigned int acl;
|
unsigned int acl;
|
||||||
|
|
||||||
if (e == NULL)
|
if (e == NULL)
|
||||||
|
|
Loading…
Reference in New Issue