[pkg-opensc-commit] [opensc] 98/295: Fix Coverity remarks (#876)
Eric Dorland
eric at moszumanska.debian.org
Sat Jun 24 21:11:20 UTC 2017
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository opensc.
commit 12f402616050e6ac943217b2170e865c1a297e77
Author: Jakuje <jakuje at gmail.com>
Date: Mon Oct 10 22:21:46 2016 +0200
Fix Coverity remarks (#876)
---
src/common/libpkcs11.c | 1 +
src/libopensc/aux-data.c | 2 ++
src/libopensc/card-asepcos.c | 9 ++-------
src/libopensc/pkcs15-cert.c | 9 +++++----
src/libopensc/pkcs15-pin.c | 2 +-
src/libopensc/pkcs15-pubkey.c | 2 ++
src/pkcs11/misc.c | 14 ++++++++------
src/tools/pkcs11-tool.c | 5 ++++-
src/tools/pkcs15-init.c | 2 ++
src/tools/pkcs15-tool.c | 8 ++++++--
10 files changed, 33 insertions(+), 21 deletions(-)
diff --git a/src/common/libpkcs11.c b/src/common/libpkcs11.c
index 17500aa..302496f 100644
--- a/src/common/libpkcs11.c
+++ b/src/common/libpkcs11.c
@@ -60,6 +60,7 @@ C_LoadModule(const char *mspec, CK_FUNCTION_LIST_PTR_PTR funcs)
fprintf(stderr, "C_GetFunctionList failed %lx", rv);
failed:
C_UnloadModule((void *) mod);
+ free(mod);
return NULL;
}
diff --git a/src/libopensc/aux-data.c b/src/libopensc/aux-data.c
index b6bda71..c81cbf5 100644
--- a/src/libopensc/aux-data.c
+++ b/src/libopensc/aux-data.c
@@ -82,6 +82,7 @@ sc_aux_data_set_md_guid(struct sc_context *ctx, struct sc_auxiliary_data *aux_da
case SC_AUX_DATA_TYPE_NO_DATA:
memset(aux_data, 0, sizeof(*aux_data));
aux_data->type = SC_AUX_DATA_TYPE_MD_CMAP_RECORD;
+ /* fallthrough */
case SC_AUX_DATA_TYPE_MD_CMAP_RECORD:
rec = &aux_data->data.cmap_record;
memcpy(rec->guid, guid, strlen(guid));
@@ -112,6 +113,7 @@ sc_aux_data_set_md_flags(struct sc_context *ctx, struct sc_auxiliary_data *aux_d
case SC_AUX_DATA_TYPE_NO_DATA:
memset(aux_data, 0, sizeof(*aux_data));
aux_data->type = SC_AUX_DATA_TYPE_MD_CMAP_RECORD;
+ /* fallthrough */
case SC_AUX_DATA_TYPE_MD_CMAP_RECORD:
aux_data->data.cmap_record.flags = flags;
sc_log(ctx, "set MD container flags '0x%X'", flags);
diff --git a/src/libopensc/card-asepcos.c b/src/libopensc/card-asepcos.c
index ad0f514..76d4396 100644
--- a/src/libopensc/card-asepcos.c
+++ b/src/libopensc/card-asepcos.c
@@ -870,13 +870,8 @@ static int asepcos_build_pin_apdu(sc_card_t *card, sc_apdu_t *apdu,
*p++ = (fileid >> 16) & 0xff;
*p++ = (fileid >> 8 ) & 0xff;
*p++ = fileid & 0xff;
- if (is_puk == 0) {
- memcpy(p, data->pin1.data, data->pin1.len);
- p += data->pin1.len;
- } else {
- memcpy(p, data->pin1.data, data->pin1.len);
- p += data->pin1.len;
- }
+ memcpy(p, data->pin1.data, data->pin1.len);
+ p += data->pin1.len;
apdu->lc = p - buf;
apdu->datalen = p - buf;
apdu->data = buf;
diff --git a/src/libopensc/pkcs15-cert.c b/src/libopensc/pkcs15-cert.c
index 390cd50..089695c 100644
--- a/src/libopensc/pkcs15-cert.c
+++ b/src/libopensc/pkcs15-cert.c
@@ -273,26 +273,27 @@ sc_pkcs15_get_extension(struct sc_context *ctx, struct sc_pkcs15_cert *cert,
LOG_FUNC_RETURN(ctx, r);
/* is it the RN we are looking for */
- if(sc_compare_oid(&oid, type) != 0) {
+ if (sc_compare_oid(&oid, type) != 0) {
if (*ext_val == NULL) {
- *ext_val= val;
+ *ext_val = val;
val = NULL;
*ext_val_len = val_len;
+ /* do not free here -- return the allocated value to caller */
}
else {
*ext_val_len = MIN(*ext_val_len, val_len);
memcpy(*ext_val, val, *ext_val_len);
+ free(val);
}
if (is_critical)
*is_critical = critical;
r = val_len;
- free(val);
LOG_FUNC_RETURN(ctx, r);
}
- free(val);
}
+ free(val);
LOG_FUNC_RETURN(ctx, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
}
diff --git a/src/libopensc/pkcs15-pin.c b/src/libopensc/pkcs15-pin.c
index 8efc605..69fd086 100644
--- a/src/libopensc/pkcs15-pin.c
+++ b/src/libopensc/pkcs15-pin.c
@@ -407,7 +407,7 @@ int sc_pkcs15_change_pin(struct sc_pkcs15_card *p15card,
struct sc_context *ctx = p15card->card->ctx;
struct sc_pin_cmd_data data;
struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
- struct sc_card *card = p15card->card;
+ struct sc_card *card;
int r;
LOG_FUNC_CALLED(ctx);
diff --git a/src/libopensc/pkcs15-pubkey.c b/src/libopensc/pkcs15-pubkey.c
index d121776..75a5782 100644
--- a/src/libopensc/pkcs15-pubkey.c
+++ b/src/libopensc/pkcs15-pubkey.c
@@ -1403,6 +1403,8 @@ sc_pkcs15_pubkey_from_spki_sequence(struct sc_context *ctx, const unsigned char
if(outpubkey)
*outpubkey = pubkey;
+ else
+ free(pubkey);
LOG_FUNC_RETURN(ctx, r);
}
diff --git a/src/pkcs11/misc.c b/src/pkcs11/misc.c
index 3d78827..02c26ed 100644
--- a/src/pkcs11/misc.c
+++ b/src/pkcs11/misc.c
@@ -178,11 +178,10 @@ CK_RV push_login_state(struct sc_pkcs11_slot *slot,
struct sc_pkcs11_login *login = NULL;
if (!sc_pkcs11_conf.atomic || !slot) {
- r = CKR_OK;
- goto err;
+ return CKR_OK;
}
- login = (struct sc_pkcs11_login *) malloc(sizeof *login);
+ login = (struct sc_pkcs11_login *) calloc(1, sizeof *login);
if (login == NULL) {
goto err;
}
@@ -199,12 +198,15 @@ CK_RV push_login_state(struct sc_pkcs11_slot *slot,
goto err;
}
+ login = NULL;
r = CKR_OK;
err:
- if (r != CKR_OK && login) {
- sc_mem_clear(login->pPin, login->ulPinLen);
- free(login->pPin);
+ if (login) {
+ if (login->pPin) {
+ sc_mem_clear(login->pPin, login->ulPinLen);
+ free(login->pPin);
+ }
free(login);
}
diff --git a/src/tools/pkcs11-tool.c b/src/tools/pkcs11-tool.c
index 7eb77a7..c05b224 100644
--- a/src/tools/pkcs11-tool.c
+++ b/src/tools/pkcs11-tool.c
@@ -1396,8 +1396,10 @@ static int change_pin(CK_SLOT_ID slot, CK_SESSION_HANDLE sess)
r = util_getpass(&new_pin, &len, stdin);
if (r < 0)
return 1;
- if (!new_pin || !*new_pin || strcmp(new_buf, new_pin) != 0)
+ if (!new_pin || !*new_pin || strcmp(new_buf, new_pin) != 0) {
+ free(new_pin);
return 1;
+ }
}
else {
new_pin = (char *) opt_new_pin;
@@ -3597,6 +3599,7 @@ static int read_object(CK_SESSION_HANDLE session)
if (opt_output)
fclose(out);
+ free(value);
if (oid_buf)
free(oid_buf);
return 1;
diff --git a/src/tools/pkcs15-init.c b/src/tools/pkcs15-init.c
index 887fa98..4e1e062 100644
--- a/src/tools/pkcs15-init.c
+++ b/src/tools/pkcs15-init.c
@@ -2486,6 +2486,7 @@ handle_option(const struct option *opt)
break;
case 'h':
util_print_usage_and_die(app_name, options, option_help, NULL);
+ /* exit */
case 'i':
opt_objectid = optarg;
break;
@@ -2829,6 +2830,7 @@ int get_pin(sc_ui_hints_t *hints, char **out)
if (!(flags & SC_UI_PIN_MISMATCH_RETRY)) {
fprintf(stderr, "PINs do not match.\n");
+ free(pin);
return SC_ERROR_KEYPAD_PIN_MISMATCH;
}
diff --git a/src/tools/pkcs15-tool.c b/src/tools/pkcs15-tool.c
index 61defab..7eeff44 100644
--- a/src/tools/pkcs15-tool.c
+++ b/src/tools/pkcs15-tool.c
@@ -1136,8 +1136,10 @@ static u8 * get_pin(const char *prompt, sc_pkcs15_object_t *pin_obj)
r = util_getpass(&pincode, &len, stdin);
if (r < 0)
return NULL;
- if (!pincode || strlen(pincode) == 0)
+ if (!pincode || strlen(pincode) == 0) {
+ free(pincode);
return NULL;
+ }
if (strlen(pincode) < pinfo->attrs.pin.min_length) {
printf("PIN code too short, try again.\n");
continue;
@@ -1146,7 +1148,7 @@ static u8 * get_pin(const char *prompt, sc_pkcs15_object_t *pin_obj)
printf("PIN code too long, try again.\n");
continue;
}
- return (u8 *) strdup(pincode);
+ return (u8 *) pincode;
}
}
@@ -1573,6 +1575,7 @@ static int change_pin(void)
if (pincode && strlen((char *) pincode) == 0) {
fprintf(stderr, "No PIN code supplied.\n");
+ free(pincode);
return 2;
}
@@ -1592,6 +1595,7 @@ static int change_pin(void)
if (newpin == NULL || strlen((char *) newpin) == 0) {
fprintf(stderr, "No new PIN value supplied.\n");
free(newpin);
+ free(pincode);
return 2;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/opensc.git
More information about the pkg-opensc-commit
mailing list