[Pcsclite-cvs-commit] CVS Drivers/ccid/src

CVS User rousseau ludovic.rousseau@free.fr
Mon, 02 May 2005 08:30:58 +0000


Update of /cvsroot/pcsclite/Drivers/ccid/src
In directory haydn:/tmp/cvs-serv20357

Modified Files:
	ccid_usb.c 
Log Message:
get_data_rates(): check that the reader sends a DATA RATES list size
multiple of 4 othewise it is an error


--- /cvsroot/pcsclite/Drivers/ccid/src/ccid_usb.c	2005/04/27 14:10:38	1.55
+++ /cvsroot/pcsclite/Drivers/ccid/src/ccid_usb.c	2005/05/02 08:30:57	1.56
@@ -18,7 +18,7 @@
 */
 
 /*
- * $Id: ccid_usb.c,v 1.55 2005/04/27 14:10:38 rousseau Exp $
+ * $Id: ccid_usb.c,v 1.56 2005/05/02 08:30:57 rousseau Exp $
  */
 
 #define __CCID_USB__
@@ -706,34 +706,28 @@
 		sizeof(buffer),
 		usbDevice[reader_index].ccid.readTimeout * 1000);
 
-	/* we got an error? */
-	if (n <= 0)
+	if ((n <= 0) /* we got an error? */
+		|| (n%4)) /* or a strange value */
 	{
 		struct usb_interface *usb_interface;
 
-		DEBUG_INFO2("IFD does not support GET_DATA_RATES request: %s",
-			strerror(errno));
+		if (n <= 0)
+			DEBUG_INFO2("IFD does not support GET_DATA_RATES request: %s",
+				strerror(errno));
 
-		/* we create a minimal array */
-		int_array = calloc(3, sizeof(int));
-		if (NULL == int_array)
-		{
-			DEBUG_CRITICAL("Memory allocation failed");
-			return NULL;
-		}
+		if (n%4)
+			DEBUG_INFO2("Wrong GET DATA RATES size: %d", n);
+
+		/* create a fake answer with only two values */
+		n = 2*4;
 
 		usb_interface = get_ccid_usb_interface(usbDevice[reader_index].dev);
 
 		/* dwDataRate (default data rate) */
-		int_array[0] = dw2i(usb_interface->altsetting->extra, 19);
+		memcpy(buffer, usb_interface->altsetting->extra +19, 4);
 
 		/* dwMaxDataRate */
-		int_array[1] = dw2i(usb_interface->altsetting->extra, 23);
-
-		/* end of array marker */
-		int_array[2] = 0;
-
-		return int_array;
+		memcpy(buffer+4, usb_interface->altsetting->extra +23, 4);
 	}
 
 	/* allocate the buffer (including the end marker) */