[Pcsclite-cvs-commit] PCSC/src hotplug_libusb.c,1.26,1.27
rousseau@haydn.debian.org
rousseau@haydn.debian.org
Update of /cvsroot/pcsclite/PCSC/src
In directory haydn:/tmp/cvs-serv25592
Modified Files:
hotplug_libusb.c
Log Message:
use a dynamic array for available USB drivers:
- avoid a buffer overflow (argh!)
- allow to use more than 16 drivers/supported readers
Index: hotplug_libusb.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/hotplug_libusb.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- hotplug_libusb.c 26 May 2004 20:53:38 -0000 1.26
+++ hotplug_libusb.c 9 Jun 2004 09:57:02 -0000 1.27
@@ -53,7 +53,7 @@
static int AraKiriHotPlug = FALSE;
/*
- * keep track of PCSCLITE_MAX_READERS_CONTEXTS simultaneous drivers
+ * keep track of drivers in a dynamically allocated array
*/
static struct _driverTracker
{
@@ -63,7 +63,8 @@
char *bundleName;
char *libraryPath;
char *readerName;
-} driverTracker[PCSCLITE_MAX_READERS_CONTEXTS];
+} *driverTracker = NULL;
+#define DRIVER_TRACKER_SIZE_STEP 8
/*
* keep track of PCSCLITE_MAX_READERS_CONTEXTS simultaneous readers
@@ -100,6 +101,15 @@
return -1;
}
+ /* allocate a first array */
+ driverTracker = calloc(DRIVER_TRACKER_SIZE_STEP, sizeof(*driverTracker));
+ if (NULL == driverTracker)
+ {
+ DebugLogA("Not enough memory");
+ return -1;
+ }
+ driverSize = DRIVER_TRACKER_SIZE_STEP;
+
while ((currFP = readdir(hpDir)) != 0)
{
if (strstr(currFP->d_name, ".bundle") != 0)
@@ -158,6 +168,23 @@
listCount++;
alias++;
+
+ if (listCount >= driverSize)
+ {
+ /* increase the array size */
+ driverSize += DRIVER_TRACKER_SIZE_STEP;
+#ifdef DEBUG_HOTPLUG
+ DebugLogB("Increase driverTracker to %d entries",
+ driverSize);
+#endif
+ driverTracker = realloc(driverTracker,
+ driverSize * sizeof(*driverTracker));
+ if (NULL == driverTracker)
+ {
+ DebugLogA("Not enough memory");
+ return -1;
+ }
+ }
}
}
}
@@ -170,6 +197,10 @@
DebugLogA("No bundle files in pcsc drivers directory: " PCSCLITE_HP_DROPDIR);
DebugLogA("Disabling USB support for pcscd");
}
+#ifdef DEBUG_HOTPLUG
+ else
+ DebugLogB("Found drivers for %d readers", listCount);
+#endif
return 0;
}
@@ -198,7 +229,7 @@
for (dev = bus->devices; dev; dev = dev->next)
{
/* check if the device is supported by one driver */
- for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++)
+ for (i=0; i<driverSize; i++)
{
if (driverTracker[i].libraryPath != NULL &&
dev->descriptor.idVendor == driverTracker[i].manuID &&
@@ -307,15 +338,6 @@
LONG HPSearchHotPluggables(void)
{
int i;
-
- for (i=0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
- {
- driverTracker[i].productID = 0;
- driverTracker[i].manuID = 0;
- driverTracker[i].bundleName = NULL;
- driverTracker[i].libraryPath = NULL;
- driverTracker[i].readerName = NULL;
- }
for (i=0; i<PCSCLITE_MAX_READERS_CONTEXTS; i++)
{