On 2/16/2011 6:21 AM, Martin Paljak wrote:
Hello,
On Feb 16, 2011, at 12:32 PM, webmas...@opensc-project.org wrote:
-----------
card-piv: 'ssize_t' is not defined when compiling with Visual Studio

(I'm on the road not connected to work PC with git and more links, but some 
comments nevertheless)

Windows does have SSIZE_T. But Windows prototype for uses int for _read(). So 
the best solution probably lies in between two options, the other one being 
mapping SSIZE_T in winconfig.h instead.

http://msdn.microsoft.com/en-US/library/ms235412(v=VS.80).aspx
http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx


The ssize_t was added in #5135 to fix other issues.

Since this is the only place in OpenSC to test the results of a read like
this, another approach would be in the attachment. This also makes sure
that there are at least 2 bytes read.

But I must agree that the use if ssize_t or SSIZE_T was designed
woujld be the more general way to solve this.






--

 Douglas E. Engert  <deeng...@anl.gov>
 Argonne National Laboratory
 9700 South Cass Avenue
 Argonne, Illinois  60439
 (630) 252-5444
Index: card-piv.c
===================================================================
--- card-piv.c	(revision 5192)
+++ card-piv.c	(working copy)
@@ -807,7 +807,6 @@
 	int r;
 	int f = -1;
 	size_t len;
-	ssize_t res;
 	u8 tagbuf[16];
 	size_t rbuflen;
 	const u8 * body;
@@ -825,13 +824,12 @@
 			r = SC_ERROR_FILE_NOT_FOUND; 
 			goto err;
 	}
-	res = read(f, tagbuf, sizeof(tagbuf)); /* get tag and length */
-	if (res < 0) {
+	len = read(f, tagbuf, sizeof(tagbuf)); /* get tag and length */
+	if (len < 2 || len > sizeof(tagbuf)) {
 		sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,"Problem with \"%s\"\n",filename);
 		r =  SC_ERROR_DATA_OBJECT_NOT_FOUND;
 		goto err;
 	}
-	len = res;
 	body = tagbuf;
 	if (sc_asn1_read_tag(&body, 0xfffff, &cla_out, 
 			&tag_out, &bodylen) != SC_SUCCESS) { 
_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to