[pkg-opensc-commit] [opensc] 202/295: Fix most of warnings shown when building on Linux and mingw

Eric Dorland eric at moszumanska.debian.org
Sat Jun 24 21:11:31 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 7f778ccff83acc555d5ca5ad185b3ed8c7971fe4
Author: Maciej S. Szmigiero <mail at maciej.szmigiero.name>
Date:   Wed Jan 25 23:27:27 2017 +0100

    Fix most of warnings shown when building on Linux and mingw
    
    This commit fixes most of warnings shown by GCC on 64-bit Linux, 32-bit and
    64-bit mingw builds (with SM and OpenSSL enabled).
    
    These warnings were mostly caused by missing casts.
    
    In minidriver there was also a bit of unused variables and dead code.
    
    Remaining warnings on mingw are mostly caused by GCC not recognizing on
    this platform "ll" size specifier (present at least since
    Visual Studio 2005, also in mingw own CRT) and "z" size specifier (this one
    will be fixed in next commits).
    
    There is also a warning about pointer truncation on Win64 when making
    PKCS#11 object handle from pointer to this object.
    This is a legitimate warning, since it could result in the same handles
    being generated from different pointers and so from different objects.
    
    Signed-off-by: Maciej S. Szmigiero <mail at maciej.szmigiero.name>
---
 src/libopensc/card-cac.c      |   9 +--
 src/libopensc/card.c          |   2 +-
 src/libopensc/ctx.c           |   3 +-
 src/libopensc/iasecc-sm.c     |   3 +-
 src/libopensc/reader-pcsc.c   |  30 +++++---
 src/minidriver/minidriver.c   | 157 +++++++-----------------------------------
 src/pkcs11/framework-pkcs15.c |   8 ++-
 src/pkcs11/pkcs11-display.c   |  15 +++-
 src/smm/Makefile.am           |   2 +-
 src/smm/sm-card-iasecc.c      |   3 +-
 src/tools/openpgp-tool.c      |   2 +-
 11 files changed, 76 insertions(+), 158 deletions(-)

diff --git a/src/libopensc/card-cac.c b/src/libopensc/card-cac.c
index d5f8585..51f5cee 100644
--- a/src/libopensc/card-cac.c
+++ b/src/libopensc/card-cac.c
@@ -430,8 +430,9 @@ static int cac_read_file(sc_card_t *card, int file_type, u8 **out_buf, size_t *o
 		goto fail;
 
 	left = size = lebytes2ushort(count);
-	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "got %d bytes out_ptr=%lx count&=%lx count[0]=0x%02x count[1]=0x%02x, len=0x%04x (%d)",
-		len, (unsigned long) out_ptr, (unsigned long)&count, count[0], count[1], size, size);
+	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
+		 "got %d bytes out_ptr=%p count&=%p count[0]=0x%02x count[1]=0x%02x, len=0x%04x (%d)",
+		 len, out_ptr, &count, count[0], count[1], size, size);
 	out = out_ptr = malloc(size);
 	if (out == NULL) {
 		r = SC_ERROR_OUT_OF_MEMORY;
@@ -983,8 +984,8 @@ static int cac_select_file_by_type(sc_card_t *card, const sc_path_t *in_path, sc
 		in_path->aid.value[4], in_path->aid.value[5], in_path->aid.value[6], in_path->aid.len,
 		in_path->value[0], in_path->value[1], in_path->value[2], in_path->value[3], in_path->len,
 		in_path->type, in_path->type);
-	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"file_out=%lx index=%d count=%d\n",(unsigned long) file_out,
-		in_path->index, in_path->count);
+	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "file_out=%p index=%d count=%d\n",
+		 file_out, in_path->index, in_path->count);
 
 	/* Sigh, sc_key_select expects paths to keys to have specific formats. There is no override.
 	 * we have to add some bytes to the path to make it happy. A better fix would be to give sc_key_file
diff --git a/src/libopensc/card.c b/src/libopensc/card.c
index 73f8ede..a661a4c 100644
--- a/src/libopensc/card.c
+++ b/src/libopensc/card.c
@@ -1243,7 +1243,7 @@ sc_card_sm_load(struct sc_card *card, const char *module_path, const char *in_mo
 	char *module = NULL;
 #ifdef _WIN32
 	char temp_path[PATH_MAX];
-	int temp_len;
+	size_t temp_len;
 	const char path_delim = '\\';
 #else
 	const char path_delim = '/';
diff --git a/src/libopensc/ctx.c b/src/libopensc/ctx.c
index 54155b4..b93e4c2 100644
--- a/src/libopensc/ctx.c
+++ b/src/libopensc/ctx.c
@@ -141,8 +141,7 @@ sc_ctx_win32_get_config_value(char *name_env, char *name_reg, char *name_key,
 #ifdef _WIN32
 	char temp[PATH_MAX + 1];
 	char *value = NULL;
-	int temp_len = PATH_MAX;
-	int rv = SC_ERROR_INTERNAL;
+	DWORD temp_len = PATH_MAX;
 	long rc;
 	HKEY hKey;
 
diff --git a/src/libopensc/iasecc-sm.c b/src/libopensc/iasecc-sm.c
index 738ca89..d92d8f1 100644
--- a/src/libopensc/iasecc-sm.c
+++ b/src/libopensc/iasecc-sm.c
@@ -20,6 +20,7 @@
  */
 
 #include <string.h>
+#include <stdint.h>
 #include <stdlib.h>
 
 #include "internal.h"
@@ -693,7 +694,7 @@ iasecc_sm_delete_file(struct sc_card *card, unsigned se_num, unsigned int file_i
 	rv = iasecc_sm_initialize(card, se_num, SM_CMD_FILE_DELETE);
 	LOG_TEST_RET(ctx, rv, "iasecc_sm_delete_file() SM INITIALIZE failed");
 
-	sm_info->cmd_data = (void *)(long)file_id;
+	sm_info->cmd_data = (void *)(uintptr_t)file_id;
 
 	sc_remote_data_init(&rdata);
 	rv = iasecc_sm_cmd(card, &rdata);
diff --git a/src/libopensc/reader-pcsc.c b/src/libopensc/reader-pcsc.c
index bc33cfc..f84c9ca 100644
--- a/src/libopensc/reader-pcsc.c
+++ b/src/libopensc/reader-pcsc.c
@@ -49,12 +49,28 @@
 
 #define SCARD_CLASS_SYSTEM     0x7fff
 #define SCARD_ATTR_VALUE(Class, Tag) ((((ULONG)(Class)) << 16) | ((ULONG)(Tag)))
+
+#ifndef SCARD_ATTR_DEVICE_FRIENDLY_NAME_A
 #define SCARD_ATTR_DEVICE_FRIENDLY_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0003)
+#endif
+
+#ifndef SCARD_ATTR_DEVICE_SYSTEM_NAME_A
 #define SCARD_ATTR_DEVICE_SYSTEM_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0004)
+#endif
+
 #define SCARD_CLASS_VENDOR_INFO 1
+
+#ifndef SCARD_ATTR_VENDOR_NAME
 #define SCARD_ATTR_VENDOR_NAME SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0100) /**< Vendor name. */
+#endif
+
+#ifndef SCARD_ATTR_VENDOR_IFD_TYPE
 #define SCARD_ATTR_VENDOR_IFD_TYPE SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0101) /**< Vendor-supplied interface device type (model designation of reader). */
+#endif
+
+#ifndef SCARD_ATTR_VENDOR_IFD_VERSION
 #define SCARD_ATTR_VENDOR_IFD_VERSION SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0102) /**< Vendor-supplied interface device version (DWORD in the form 0xMMmmbbbb where MM = major version, mm = minor version, and bbbb = build number). */
+#endif
 
 /* Logging */
 #define PCSC_TRACE(reader, desc, rv) do { sc_log(reader->ctx, "%s:" desc ": 0x%08lx\n", reader->name, (unsigned long)((ULONG)rv)); } while (0)
@@ -836,7 +852,7 @@ static int pcsc_finish(sc_context_t *ctx)
 	LOG_FUNC_CALLED(ctx);
 
 	if (gpriv) {
-		if (gpriv->pcsc_ctx != -1 && !(ctx->flags & SC_CTX_FLAG_TERMINATE))
+		if (gpriv->pcsc_ctx != (SCARDCONTEXT)-1 && !(ctx->flags & SC_CTX_FLAG_TERMINATE))
 			gpriv->SCardReleaseContext(gpriv->pcsc_ctx);
 		if (gpriv->dlhandle != NULL)
 			sc_dlclose(gpriv->dlhandle);
@@ -1170,7 +1186,7 @@ static int pcsc_detect_readers(sc_context_t *ctx)
 	sc_log(ctx, "Probing PC/SC readers");
 
 	do {
-		if (gpriv->pcsc_ctx == -1) {
+		if (gpriv->pcsc_ctx == (SCARDCONTEXT)-1) {
 			/*
 			 * Cannot call SCardListReaders with -1
 			 * context as in Windows ERROR_INVALID_HANDLE
@@ -1220,7 +1236,7 @@ static int pcsc_detect_readers(sc_context_t *ctx)
 		goto out;
 	}
 	for (reader_name = reader_buf; *reader_name != '\x0'; reader_name += strlen(reader_name) + 1) {
-		sc_reader_t *reader = NULL, *old_reader;
+		sc_reader_t *reader = NULL, *old_reader = NULL;
 		struct pcsc_private_data *priv = NULL;
 		scconf_block *conf_block = NULL;
 		int found = 0;
@@ -2226,8 +2242,6 @@ static int cardmod_connect(sc_reader_t *reader)
 
 static int cardmod_disconnect(sc_reader_t * reader)
 {
-	struct pcsc_private_data *priv = GET_PRIV_DATA(reader);
-
 	reader->flags = 0;
 	return SC_SUCCESS;
 }
@@ -2334,8 +2348,8 @@ int cardmod_use_reader(sc_context_t *ctx, void * pcsc_context_handle, void * pcs
 	scconf_block *conf_block = NULL;
 	struct pcsc_global_private_data *gpriv = (struct pcsc_global_private_data *) ctx->reader_drv_data;
 	LONG rv;
-	char reader_name[128];
-	DWORD rcount, feature_len, display_ioctl, reader_name_size = sizeof(reader_name);
+	BYTE reader_name[128];
+	DWORD rcount, feature_len, display_ioctl = 0, reader_name_size = sizeof(reader_name);
 	int ret = SC_ERROR_INTERNAL;
 	unsigned int i;
 
@@ -2384,7 +2398,7 @@ int cardmod_use_reader(sc_context_t *ctx, void * pcsc_context_handle, void * pcs
 		reader->drv_data = priv;
 		reader->ops = &cardmod_ops;
 		reader->driver = &cardmod_drv;
-		if ((reader->name = strdup(reader_name)) == NULL) {
+		if ((reader->name = strdup((const char *)reader_name)) == NULL) {
 			ret = SC_ERROR_OUT_OF_MEMORY;
 			goto err1;
 		}
diff --git a/src/minidriver/minidriver.c b/src/minidriver/minidriver.c
index 807f059..6724bd4 100644
--- a/src/minidriver/minidriver.c
+++ b/src/minidriver/minidriver.c
@@ -241,7 +241,6 @@ static const struct sc_asn1_entry c_asn1_md_container[C_ASN1_MD_CONTAINER_SIZE]
 
 static int associate_card(PCARD_DATA pCardData);
 static int disassociate_card(PCARD_DATA pCardData);
-static DWORD md_get_cardcf(PCARD_DATA pCardData, CARD_CACHE_FILE_FORMAT **out);
 static DWORD md_pkcs15_delete_object(PCARD_DATA pCardData, struct sc_pkcs15_object *obj);
 static DWORD md_fs_init(PCARD_DATA pCardData);
 
@@ -327,17 +326,6 @@ static void loghex(PCARD_DATA pCardData, int level, PBYTE data, size_t len)
 		logprintf(pCardData, level, " %04X  %s\n", a, line);
 }
 
-static void print_werror(PCARD_DATA pCardData, PSTR str)
-{
-	void *buf;
-	FormatMessageA(
-		FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
-		NULL, GetLastError(), 0, (LPSTR) &buf, 0, NULL);
-
-	logprintf(pCardData, 0, "%s%s\n", str, (PSTR) buf);
-	LocalFree(buf);
-}
-
 /*
  * check if the card has been removed, or the
  * caller has changed the handles.
@@ -532,25 +520,6 @@ md_is_supports_container_key_import(PCARD_DATA pCardData)
 	return md_get_config_bool(pCardData, "md_supports_container_key_import", MD_STATIC_FLAG_CREATE_CONTAINER_KEY_IMPORT, TRUE);
 }
 
-
-/* Check if specified PIN has been verified */
-static BOOL
-md_is_pin_set(PCARD_DATA pCardData, DWORD role)
-{
-	VENDOR_SPECIFIC *vs;
-	CARD_CACHE_FILE_FORMAT *cardcf = NULL;
-
-	if (!pCardData)
-		return FALSE;
-	vs = pCardData->pvVendorSpecific;
-
-	if (md_get_cardcf(pCardData, &cardcf) != SCARD_S_SUCCESS)
-		return FALSE;
-
-	return IS_PIN_SET(cardcf->bPinsFreshness, role);
-}
-
-
 /* generate unique key label (GUID)*/
 static VOID md_generate_guid( __in_ecount(MAX_CONTAINER_NAME_LEN+1) PSTR szGuid) {
 	RPC_CSTR szRPCGuid = NULL;
@@ -618,21 +587,6 @@ md_contguid_delete_conversion(PCARD_DATA pCardData, __in_ecount(MAX_CONTAINER_NA
 	}
 }
 
-/* this function take the guid in input and search if it should be replaced
-Return if it has been replaced or not */
-static BOOL
-md_contguid_find_conversion(PCARD_DATA pCardData, __in_ecount(MAX_CONTAINER_NAME_LEN+1) PSTR szGuid)
-{
-	int i;
-	for (i = 0; i < MD_MAX_CONVERSIONS; i++) {
-		if (strcmp(md_static_conversions[i].szOpenSCGuid,szGuid) == 0) {
-			strcpy_s(szGuid, MAX_CONTAINER_NAME_LEN+1, md_static_conversions[i].szWindowsGuid);
-			return TRUE;
-		}
-	}
-	return FALSE;
-}
-
 /* build key args from the minidriver guid */
 static VOID
 md_contguid_build_key_args_from_cont_guid(PCARD_DATA pCardData, __in_ecount(MAX_CONTAINER_NAME_LEN+1) PSTR szGuid,
@@ -658,12 +612,9 @@ md_contguid_build_key_args_from_cont_guid(PCARD_DATA pCardData, __in_ecount(MAX_
 static DWORD
 md_contguid_build_cont_guid_from_key(PCARD_DATA pCardData, struct sc_pkcs15_object *key_obj, __in_ecount(MAX_CONTAINER_NAME_LEN+1) PSTR szGuid)
 {
-	VENDOR_SPECIFIC *vs;
 	struct sc_pkcs15_prkey_info *prkey_info = (struct sc_pkcs15_prkey_info *)key_obj->data;
 	DWORD dwret = SCARD_S_SUCCESS;
 
-	vs = (VENDOR_SPECIFIC*) pCardData->pvVendorSpecific;
-
 	szGuid[0] = '\0';
 	/* priorize the use of the key id over the key label as a container name */
 	if (md_is_guid_as_id(pCardData) && prkey_info->id.len > 0 && prkey_info->id.len <= MAX_CONTAINER_NAME_LEN)  {
@@ -724,7 +675,7 @@ md_fs_find_directory(PCARD_DATA pCardData, struct md_directory *parent, char *na
 		dir = parent->subdirs;
 		while(dir)   {
 			if (strlen(name) > sizeof dir->name
-					|| !strncmp(dir->name, name, sizeof dir->name))
+					|| !strncmp((char *)dir->name, name, sizeof dir->name))
 				break;
 			dir = dir->next;
 		}
@@ -756,7 +707,7 @@ md_fs_add_directory(PCARD_DATA pCardData, struct md_directory **head, char *name
 		return SCARD_E_NO_MEMORY;
 	memset(new_dir, 0, sizeof(struct md_directory));
 
-	strncpy_s(new_dir->name, sizeof(new_dir->name), name, sizeof(new_dir->name) - 1);
+	strncpy_s((char *)new_dir->name, sizeof(new_dir->name), name, sizeof(new_dir->name) - 1);
 	new_dir->acl = acl;
 
 	if (*head == NULL)   {
@@ -780,7 +731,6 @@ md_fs_add_directory(PCARD_DATA pCardData, struct md_directory **head, char *name
 static DWORD
 md_fs_find_file(PCARD_DATA pCardData, char *parent, char *name, struct md_file **out)
 {
-	VENDOR_SPECIFIC *vs;
 	struct md_file *file = NULL;
 	struct md_directory *dir = NULL;
 	DWORD dwret;
@@ -791,8 +741,6 @@ md_fs_find_file(PCARD_DATA pCardData, char *parent, char *name, struct md_file *
 	if (!pCardData || !name)
 		return SCARD_E_INVALID_PARAMETER;
 
-	vs = pCardData->pvVendorSpecific;
-
 	dwret = md_fs_find_directory(pCardData, NULL, parent, &dir);
 	if (dwret != SCARD_S_SUCCESS)   {
 		logprintf(pCardData, 2, "find directory '%s' error: %X\n", parent ? parent : "<null>", dwret);
@@ -805,7 +753,7 @@ md_fs_find_file(PCARD_DATA pCardData, char *parent, char *name, struct md_file *
 
 	for (file = dir->files; file!=NULL;)   {
 		if (sizeof file->name < strlen(name)
-				|| !strncmp(file->name, name, sizeof file->name))
+				|| !strncmp((char *)file->name, name, sizeof file->name))
 			break;
 		file = file->next;
 	}
@@ -834,7 +782,7 @@ md_fs_add_file(PCARD_DATA pCardData, struct md_file **head, char *name, CARD_FIL
 		return SCARD_E_NO_MEMORY;
 	memset(new_file, 0, sizeof(struct md_file));
 
-	strncpy_s(new_file->name, sizeof(new_file->name), name, sizeof(new_file->name) - 1);
+	strncpy_s((char *)new_file->name, sizeof(new_file->name), name, sizeof(new_file->name) - 1);
 	new_file->size = size;
 	new_file->acl = acl;
 
@@ -911,7 +859,7 @@ md_fs_delete_file(PCARD_DATA pCardData, char *parent, char *name)
 	}
 
 	if (sizeof dir->files->name < strlen(name)
-			|| !strncmp(dir->files->name, name, sizeof dir->files->name))   {
+			|| !strncmp((char *)dir->files->name, name, sizeof dir->files->name))   {
 		file_to_rm = dir->files;
 		dir->files = dir->files->next;
 		md_fs_free_file(pCardData, file_to_rm);
@@ -922,7 +870,7 @@ md_fs_delete_file(PCARD_DATA pCardData, char *parent, char *name)
 			if (!file->next)
 				break;
 			if (sizeof file->next->name < strlen(name)
-					|| !strncmp(file->next->name, name, sizeof file->next->name))   {
+					|| !strncmp((char *)file->next->name, name, sizeof file->next->name))   {
 				file_to_rm = file->next;
 				file->next = file->next->next;
 				md_fs_free_file(pCardData, file_to_rm);
@@ -995,7 +943,6 @@ md_pkcs15_update_containers(PCARD_DATA pCardData, unsigned char *blob, size_t si
 {
 	VENDOR_SPECIFIC *vs;
 	CONTAINER_MAP_RECORD *pp;
-	DWORD dwret = SCARD_F_INTERNAL_ERROR;
 	int nn_records, idx;
 
 	if (!pCardData || !blob || size < sizeof(CONTAINER_MAP_RECORD))
@@ -1109,7 +1056,7 @@ md_fs_set_content(PCARD_DATA pCardData, struct md_file *file, unsigned char *blo
 	CopyMemory(file->blob, blob, size);
 	file->size = size;
 
-	if (!strcmp(file->name, "cmapfile"))
+	if (!strcmp((char *)file->name, "cmapfile"))
 		return md_pkcs15_update_containers(pCardData, blob, size);
 
 	return SCARD_S_SUCCESS;
@@ -1167,14 +1114,12 @@ md_fs_read_msroots_file(PCARD_DATA pCardData, char *parent, struct md_file *file
 {
 	CERT_BLOB dbStore = {0};
 	HCERTSTORE hCertStore = NULL;
-	DWORD dwret = 0;
 	VENDOR_SPECIFIC *vs;
 	int rv, ii, cert_num;
 	struct sc_pkcs15_object *prkey_objs[MD_MAX_KEY_CONTAINERS];
 
 	hCertStore = CertOpenStore(CERT_STORE_PROV_MEMORY, X509_ASN_ENCODING, (HCRYPTPROV_LEGACY) NULL, 0, NULL);
 	if (!hCertStore) {
-		dwret = GetLastError();
 		goto Ret;
 	}
 
@@ -1213,14 +1158,12 @@ md_fs_read_msroots_file(PCARD_DATA pCardData, char *parent, struct md_file *file
 			CERT_STORE_SAVE_TO_MEMORY,
 				&dbStore,
 		0)) {
-		dwret = GetLastError();
 		goto Ret;
 	}
 
 	dbStore.pbData = (PBYTE) pCardData->pfnCspAlloc(dbStore.cbData);
 
 	if (NULL == dbStore.pbData) {
-		dwret = ERROR_NOT_ENOUGH_MEMORY;
 		goto Ret;
 	}
 
@@ -1231,7 +1174,6 @@ md_fs_read_msroots_file(PCARD_DATA pCardData, char *parent, struct md_file *file
 				&dbStore,
 				0))
 	{
-		dwret = GetLastError();
 		goto Ret;
 	}
 	file->size = dbStore.cbData;
@@ -1272,12 +1214,12 @@ md_fs_read_content(PCARD_DATA pCardData, char *parent, struct md_file *file)
 		return;
 	}
 
-	if (!strcmp(dir->name, "mscp"))   {
+	if (!strcmp((char *)dir->name, "mscp"))   {
 		int idx, rv;
 
-		if(sscanf_s(file->name, "ksc%d", &idx) > 0)   {
+		if(sscanf_s((char *)file->name, "ksc%d", &idx) > 0)   {
 		}
-		else if(sscanf_s(file->name, "kxc%d", &idx) > 0)   {
+		else if(sscanf_s((char *)file->name, "kxc%d", &idx) > 0)   {
 		}
 		else   {
 			idx = -1;
@@ -1300,7 +1242,7 @@ md_fs_read_content(PCARD_DATA pCardData, char *parent, struct md_file *file)
 			CopyMemory(file->blob, cert->data.value, cert->data.len);
 			sc_pkcs15_free_certificate(cert);
 		}
-		if (!strcmp(file->name, "msroots")) {
+		if (!strcmp((char *)file->name, "msroots")) {
 			md_fs_read_msroots_file(pCardData, parent, file);
 		}
 	}
@@ -1319,17 +1261,12 @@ md_fs_read_content(PCARD_DATA pCardData, char *parent, struct md_file *file)
 static DWORD
 md_set_cardcf(PCARD_DATA pCardData, struct md_file *file)
 {
-	VENDOR_SPECIFIC *vs;
-	char *last_update = NULL;
 	CARD_CACHE_FILE_FORMAT empty = {0};
-	size_t empty_len = sizeof(empty);
 	DWORD dwret;
 
 	if (!pCardData || !file)
 		return SCARD_E_INVALID_PARAMETER;
 
-	vs = pCardData->pvVendorSpecific;
-
 	dwret = md_fs_set_content(pCardData, file, (unsigned char *)(&empty), MD_CARDCF_LENGTH);
 	if (dwret != SCARD_S_SUCCESS)
 		return dwret;
@@ -1339,31 +1276,6 @@ md_set_cardcf(PCARD_DATA pCardData, struct md_file *file)
 	return SCARD_S_SUCCESS;
 }
 
-/*
- * Return content of the 'soft' 'cardcf' file
- */
-static DWORD
-md_get_cardcf(PCARD_DATA pCardData, CARD_CACHE_FILE_FORMAT **out)
-{
-	struct md_file *file = NULL;
-
-	if (!pCardData)
-		return SCARD_E_INVALID_PARAMETER;
-
-	md_fs_find_file(pCardData, NULL, "cardcf", &file);
-	if (!file)   {
-		logprintf(pCardData, 2, "file 'cardcf' not found\n");
-		return SCARD_E_FILE_NOT_FOUND;
-	}
-	if (!file->blob || file->size < MD_CARDCF_LENGTH)
-		return SCARD_E_INVALID_VALUE;
-	if (out)
-		*out = (CARD_CACHE_FILE_FORMAT *)file->blob;
-
-	return SCARD_S_SUCCESS;
-}
-
-
 static DWORD
 md_set_cardapps(PCARD_DATA pCardData, struct md_file *file)
 {
@@ -1429,7 +1341,6 @@ md_set_cmapfile(PCARD_DATA pCardData, struct md_file *file)
 {
 	VENDOR_SPECIFIC *vs;
 	PCONTAINER_MAP_RECORD p;
-	sc_pkcs15_pubkey_t *pubkey = NULL;
 	unsigned char *cmap_buf = NULL;
 	size_t cmap_len;
 	DWORD dwret;
@@ -1459,7 +1370,7 @@ md_set_cmapfile(PCARD_DATA pCardData, struct md_file *file)
 
 	/* Initialize the P15 container array with the existing keys */
 	for(ii = 0; ii < conts_num; ii++)   {
-		struct sc_pkcs15_object *key_obj = prkey_objs[ii], *cert_obj = NULL;
+		struct sc_pkcs15_object *key_obj = prkey_objs[ii];
 		struct sc_pkcs15_prkey_info *prkey_info = (struct sc_pkcs15_prkey_info *)key_obj->data;
 		struct md_pkcs15_container *cont = &vs->p15_containers[ii];
 
@@ -1566,8 +1477,6 @@ md_set_cmapfile(PCARD_DATA pCardData, struct md_file *file)
 		/* Initialize 'CMAPFILE' content from the P15 containers */
 		p = (PCONTAINER_MAP_RECORD)cmap_buf;
 		for (ii=0; ii<MD_MAX_KEY_CONTAINERS; ii++)   {
-			struct sc_pkcs15_object *cert_obj = NULL;
-
 			if (!(vs->p15_containers[ii].flags & CONTAINER_MAP_VALID_CONTAINER))
 				continue;
 
@@ -1930,15 +1839,15 @@ md_pkcs15_generate_key(PCARD_DATA pCardData, DWORD idx, DWORD key_type, DWORD ke
 		if ((key_type == AT_ECDSA_P256)|| (key_type == AT_ECDHE_P256)) {
 			keygen_args.prkey_args.key.u.ec.params.named_curve = "secp256r1";
 			keygen_args.prkey_args.key.u.ec.params.der.len = 10;
-			keygen_args.prkey_args.key.u.ec.params.der.value = "\x06\x08\x2A\x86\x48\xCE\x3D\x03\x01\x07";
+			keygen_args.prkey_args.key.u.ec.params.der.value = (unsigned char *)"\x06\x08\x2A\x86\x48\xCE\x3D\x03\x01\x07";
 		} else if ((key_type == AT_ECDSA_P384)|| (key_type == AT_ECDHE_P384)) {
 			keygen_args.prkey_args.key.u.ec.params.named_curve = "secp384r1";
 			keygen_args.prkey_args.key.u.ec.params.der.len = 7;
-			keygen_args.prkey_args.key.u.ec.params.der.value = "\x06\x05\x2B\x81\x04\x00\x22";
+			keygen_args.prkey_args.key.u.ec.params.der.value = (unsigned char *)"\x06\x05\x2B\x81\x04\x00\x22";
 		} else if ((key_type == AT_ECDSA_P521)|| (key_type == AT_ECDHE_P521)) {
 			keygen_args.prkey_args.key.u.ec.params.named_curve = "secp521r1";
 			keygen_args.prkey_args.key.u.ec.params.der.len = 7;
-			keygen_args.prkey_args.key.u.ec.params.der.value = "\x06\x05\x2B\x81\x04\x00\x23";
+			keygen_args.prkey_args.key.u.ec.params.der.value = (unsigned char *)"\x06\x05\x2B\x81\x04\x00\x23";
 		}
 	}
 
@@ -2033,7 +1942,7 @@ md_pkcs15_store_key(PCARD_DATA pCardData, DWORD idx, DWORD key_type, BYTE *blob,
 	vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific);
 	card = vs->p15card->card;
 
-	pkey = b2i_PrivateKey(&ptr, blob_size);
+	pkey = b2i_PrivateKey((const unsigned char **)&ptr, blob_size);
 	if (!pkey)   {
 		logprintf(pCardData, 1, "MdStoreKey() MSBLOB key parse error");
 		return SCARD_E_INVALID_PARAMETER;
@@ -2172,10 +2081,9 @@ md_pkcs15_store_certificate(PCARD_DATA pCardData, char *file_name, unsigned char
 
 	/* use container's ID as ID of certificate to store */
 	idx = -1;
-	if(sscanf_s(file_name, "ksc%d", &idx) > 0)
-		;
-	else if(sscanf_s(file_name, "kxc%d", &idx) > 0)
-		;
+	if(sscanf_s(file_name, "ksc%d", &idx) > 0) {
+	} else if(sscanf_s(file_name, "kxc%d", &idx) > 0) {
+	}
 
 	if (idx >= 0 && idx < MD_MAX_KEY_CONTAINERS)   {
 		cont = &(vs->p15_containers[idx]);
@@ -2223,7 +2131,7 @@ md_query_key_sizes(PCARD_DATA pCardData, DWORD dwKeySpec, CARD_KEY_SIZES *pKeySi
 {
 	VENDOR_SPECIFIC *vs = NULL;
 	struct sc_algorithm_info* algo_info;
-	int count = 0, i, key_algo = 0, keysize = 0, flag;
+	int count = 0, i, keysize = 0, flag;
 	if (!pKeySizes)
 		return SCARD_E_INVALID_PARAMETER;
 
@@ -2453,7 +2361,6 @@ md_dialog_perform_pin_operation(PCARD_DATA pCardData, int operation, struct sc_p
 {
 	LONG_PTR parameter[10];
 	INT_PTR result = 0;
-	HWND hWndDlg = 0;
 	int rv = 0;
 	VENDOR_SPECIFIC* pv = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific);
 	/* stack the parameters */
@@ -2652,12 +2559,10 @@ DWORD WINAPI CardCreateContainer(__in PCARD_DATA pCardData,
 	__in DWORD dwKeySize,
 	__in PBYTE pbKeyData)
 {
-	VENDOR_SPECIFIC *vs = NULL;
 	DWORD dwret;
 
 	if (!pCardData)
 		return SCARD_E_INVALID_PARAMETER;
-	vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific);
 
 	logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData);
 	logprintf(pCardData, 1, "CardCreateContainer(idx:%i,flags:%X,type:%X,size:%i,data:%p)\n",
@@ -2745,7 +2650,7 @@ DWORD WINAPI CardGetContainerInfo(__in PCARD_DATA pCardData, __in BYTE bContaine
 		return SCARD_E_INVALID_PARAMETER;
 	if (bContainerIndex >= MD_MAX_KEY_CONTAINERS)
 		return SCARD_E_NO_KEY_CONTAINER;
-	if (pContainerInfo->dwVersion < 0 || pContainerInfo->dwVersion >  CONTAINER_INFO_CURRENT_VERSION)
+	if (pContainerInfo->dwVersion > CONTAINER_INFO_CURRENT_VERSION)
 		return ERROR_REVISION_MISMATCH;
 
 	pContainerInfo->dwVersion = CONTAINER_INFO_CURRENT_VERSION;
@@ -3189,8 +3094,6 @@ DWORD WINAPI CardReadFile(__in PCARD_DATA pCardData,
 	__deref_out_bcount_opt(*pcbData) PBYTE *ppbData,
 	__out PDWORD pcbData)
 {
-	VENDOR_SPECIFIC *vs;
-	struct md_directory *dir = NULL;
 	struct md_file *file = NULL;
 
 	logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData);
@@ -3201,8 +3104,6 @@ DWORD WINAPI CardReadFile(__in PCARD_DATA pCardData,
 	if (!ppbData || !pcbData)
 		return SCARD_E_INVALID_PARAMETER;
 
-	vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific);
-
 	logprintf(pCardData, 2, "pszDirectoryName = %s, pszFileName = %s, dwFlags = %X, pcbData=%u, *ppbData=%X\n",
 		NULLSTR(pszDirectoryName), NULLSTR(pszFileName), dwFlags, *pcbData, *ppbData);
 
@@ -3290,7 +3191,6 @@ DWORD WINAPI CardDeleteFile(__in PCARD_DATA pCardData,
 	__in LPSTR pszFileName,
 	__in DWORD dwFlags)
 {
-	struct md_file *file = NULL;
 	DWORD dwret;
 
 	logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData);
@@ -3351,8 +3251,8 @@ DWORD WINAPI CardEnumFiles(__in PCARD_DATA pCardData,
 	file = dir->files;
 	for (offs = 0; file != NULL && offs < sizeof(mstr) - 10;)   {
 		logprintf(pCardData, 2, "enum files(): file name '%s'\n", file->name);
-		strcpy_s(mstr+offs, sizeof(mstr) - offs, file->name);
-		offs += strlen(file->name) + 1;
+		strcpy_s(mstr+offs, sizeof(mstr) - offs, (char *)file->name);
+		offs += strlen((char *)file->name) + 1;
 		file = file->next;
 	}
 	mstr[offs] = 0;
@@ -3373,15 +3273,11 @@ DWORD WINAPI CardGetFileInfo(__in PCARD_DATA pCardData,
 	__in LPSTR pszFileName,
 	__inout PCARD_FILE_INFO pCardFileInfo)
 {
-	VENDOR_SPECIFIC *vs = NULL;
-	struct md_directory *dir = NULL;
 	struct md_file *file = NULL;
 
 	logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData);
 	logprintf(pCardData, 1, "CardGetFileInfo(dirName:'%s',fileName:'%s', out %p)\n", NULLSTR(pszDirectoryName), NULLSTR(pszFileName), pCardFileInfo);
 
-	vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific);
-
 	md_fs_find_file(pCardData, pszDirectoryName, pszFileName, &file);
 	if (!file)   {
 		logprintf(pCardData, 2, "CardWriteFile(): file '%s' not found in '%s'\n", NULLSTR(pszFileName), NULLSTR(pszDirectoryName));
@@ -3399,7 +3295,6 @@ DWORD WINAPI CardGetFileInfo(__in PCARD_DATA pCardData,
 DWORD WINAPI CardQueryFreeSpace(__in PCARD_DATA pCardData, __in DWORD dwFlags,
 	__inout PCARD_FREE_SPACE_INFO pCardFreeSpaceInfo)
 {
-	VENDOR_SPECIFIC *vs;
 	DWORD dwret;
 
 	logprintf(pCardData, 1, "\nP:%d T:%d pCardData:%p ",GetCurrentProcessId(), GetCurrentThreadId(), pCardData);
@@ -3409,8 +3304,6 @@ DWORD WINAPI CardQueryFreeSpace(__in PCARD_DATA pCardData, __in DWORD dwFlags,
 	if (!pCardData)
 		return SCARD_E_INVALID_PARAMETER;
 
-	vs = (VENDOR_SPECIFIC*)(pCardData->pvVendorSpecific);
-
 	check_reader_status(pCardData);
 
 	dwret = md_free_space(pCardData, pCardFreeSpaceInfo);
@@ -3461,7 +3354,6 @@ DWORD WINAPI CardRSADecrypt(__in PCARD_DATA pCardData,
 	VENDOR_SPECIFIC *vs;
 	struct sc_pkcs15_prkey_info *prkey_info;
 	BYTE *pbuf = NULL, *pbuf2 = NULL;
-	DWORD lg= 0, lg2 = 0;
 	struct sc_pkcs15_object *pkey = NULL;
 	struct sc_algorithm_info *alg_info = NULL;
 
@@ -3506,7 +3398,6 @@ DWORD WINAPI CardRSADecrypt(__in PCARD_DATA pCardData,
 	if (!pbuf)
 		return SCARD_E_NO_MEMORY;
 
-	lg2 = pInfo->cbData;
 	pbuf2 = pCardData->pfnCspAlloc(pInfo->cbData);
 	if (!pbuf2) {
 		pCardData->pfnCspFree(pbuf);
@@ -4355,7 +4246,6 @@ DWORD WINAPI CardDeriveKey(__in PCARD_DATA pCardData,
 	__inout PCARD_DERIVE_KEY pAgreementInfo)
 {
 	VENDOR_SPECIFIC *vs;
-	DWORD dwAgreementIndex = 0;
 	struct md_dh_agreement* agreement = NULL;
 	NCryptBufferDesc* parameters = NULL;
 	ULONG i;
@@ -4977,7 +4867,6 @@ DWORD WINAPI CardGetProperty(__in PCARD_DATA pCardData,
 	else if (wcscmp(CP_CARD_SERIAL_NO, wszProperty) == 0)   {
 		unsigned char buf[64];
 		size_t buf_len = sizeof(buf);
-		size_t sn_len = strlen(vs->p15card->tokeninfo->serial_number)/2;
 
 		if (sc_hex_to_bin(vs->p15card->tokeninfo->serial_number, buf, &buf_len))   {
 			buf_len = strlen(vs->p15card->tokeninfo->serial_number);
diff --git a/src/pkcs11/framework-pkcs15.c b/src/pkcs11/framework-pkcs15.c
index 0c89d47..545a22f 100644
--- a/src/pkcs11/framework-pkcs15.c
+++ b/src/pkcs11/framework-pkcs15.c
@@ -878,6 +878,8 @@ pkcs15_add_object(struct sc_pkcs11_slot *slot, struct pkcs15_any_object *obj,
 {
 	unsigned int i;
 	struct pkcs15_fw_data *card_fw_data;
+	CK_OBJECT_HANDLE handle =
+		(CK_OBJECT_HANDLE)obj; /* cast pointer to long, will truncate on Win64 */
 
 	if (obj == NULL || slot == NULL)
 		return;
@@ -888,11 +890,11 @@ pkcs15_add_object(struct sc_pkcs11_slot *slot, struct pkcs15_any_object *obj,
 		return;
 
 	if (pHandle != NULL)
-		*pHandle = (CK_OBJECT_HANDLE)obj; /* cast pointer to long */
+		*pHandle = handle;
 
 	list_append(&slot->objects, obj);
-	sc_log(context, "Slot:%X Setting object handle of 0x%lx to 0x%lx", slot->id, obj->base.handle, (CK_OBJECT_HANDLE)obj);
-	obj->base.handle = (CK_OBJECT_HANDLE)obj; /* cast pointer to long */
+	sc_log(context, "Slot:%X Setting object handle of 0x%lx to 0x%lx", slot->id, obj->base.handle, handle);
+	obj->base.handle = handle;
 	obj->base.flags |= SC_PKCS11_OBJECT_SEEN;
 	obj->refcount++;
 
diff --git a/src/pkcs11/pkcs11-display.c b/src/pkcs11/pkcs11-display.c
index 652c6f6..a05a7f9 100644
--- a/src/pkcs11/pkcs11-display.c
+++ b/src/pkcs11/pkcs11-display.c
@@ -18,6 +18,9 @@
  */
 
 #include "config.h"
+#if !defined(_MSC_VER) || _MSC_VER >= 1800
+#include <inttypes.h>
+#endif
 #include <string.h>
 
 #ifdef ENABLE_OPENSSL
@@ -90,10 +93,18 @@ buf_spec(CK_VOID_PTR buf_addr, CK_ULONG buf_len)
 {
 	static char ret[64];
 
+#if !defined(_MSC_VER) || _MSC_VER >= 1800
+	const size_t prwidth = sizeof(CK_VOID_PTR) * 2;
+
+	sprintf(ret, "%0*"PRIxPTR" / %lu", (int) prwidth, (uintptr_t) buf_addr,
+		buf_len);
+#else
 	if (sizeof(CK_VOID_PTR) == 4)
-		sprintf(ret, "%08lx / %ld", (unsigned long) buf_addr, (CK_LONG) buf_len);
+		sprintf(ret, "%08lx / %lu", (unsigned long) buf_addr, buf_len);
 	else
-		sprintf(ret, "%016lx / %ld", (unsigned long) buf_addr, (CK_LONG) buf_len);
+		sprintf(ret, "%016llx / %lu", (unsigned long long) buf_addr,
+			buf_len);
+#endif
 
 	return ret;
 }
diff --git a/src/smm/Makefile.am b/src/smm/Makefile.am
index 7c707ca..d63606d 100644
--- a/src/smm/Makefile.am
+++ b/src/smm/Makefile.am
@@ -19,6 +19,6 @@ libsmm_local_la_SOURCES = smm-local.c sm-module.h \
 	sm-card-authentic.c sm-card-iasecc.c \
 	smm-local.exports
 libsmm_local_la_LIBADD = $(OPTIONAL_OPENSSL_LIBS) ../libopensc/libopensc.la
-libsmm_local_la_LDFLAGS = -version-info @OPENSC_LT_CURRENT@:@OPENSC_LT_REVISION@:@OPENSC_LT_AGE@
+libsmm_local_la_LDFLAGS = -no-undefined -version-info @OPENSC_LT_CURRENT@:@OPENSC_LT_REVISION@:@OPENSC_LT_AGE@
 
 # noinst_HEADERS = sm.h
diff --git a/src/smm/sm-card-iasecc.c b/src/smm/sm-card-iasecc.c
index d9770d7..89860d2 100644
--- a/src/smm/sm-card-iasecc.c
+++ b/src/smm/sm-card-iasecc.c
@@ -22,6 +22,7 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -185,7 +186,7 @@ sm_iasecc_get_apdu_create_file(struct sc_context *ctx, struct sm_info *sm_info,
 static int
 sm_iasecc_get_apdu_delete_file(struct sc_context *ctx, struct sm_info *sm_info, struct sc_remote_data *rdata)
 {
-	unsigned int file_id = (unsigned int)(long)sm_info->cmd_data;
+	unsigned int file_id = (unsigned int)(uintptr_t)sm_info->cmd_data;
 	struct sc_remote_apdu *rapdu = NULL;
 	int rv;
 
diff --git a/src/tools/openpgp-tool.c b/src/tools/openpgp-tool.c
index 920a2dc..e1fa256 100644
--- a/src/tools/openpgp-tool.c
+++ b/src/tools/openpgp-tool.c
@@ -654,7 +654,7 @@ int main(int argc, char **argv)
 		#ifndef _WIN32
 		execv(exec_program, largv);
 		#else
-		_execv(exec_program, largv);
+		_execv(exec_program, (const char * const*)largv);
 		#endif
 		/* we should not get here */
 		perror("execv()");

-- 
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