lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <200607251634.13437.bjorn.helgaas@hp.com>
Date:	Tue, 25 Jul 2006 16:34:13 -0600
From:	Bjorn Helgaas <bjorn.helgaas@...com>
To:	Andrew Morton <akpm@...l.org>
Cc:	Samuel Ortiz <samuel@...tiz.org>, irda-users@...ts.sourceforge.net,
	Dag Brattli <dagb@...uit.no>, sda@...t.de,
	Benjamin Kong <benjamin_kong@....com.tw>,
	Clear Zhang <clear_zhang@....com.tw>,
	linux-kernel@...r.kernel.org
Subject: [PATCH] IRDA: Replace hard-coded dev_self[] array sizes with ARRAY_SIZE()

Several IR drivers used "for (i = 0; i < 4; i++)" to walk their
dev_self[] table.  Better to use ARRAY_SIZE().  And fix ali-ircc
so it won't run off the end if we find too many adapters.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@...com>

Index: work-mm2/drivers/net/irda/w83977af_ir.c
===================================================================
--- work-mm2.orig/drivers/net/irda/w83977af_ir.c	2006-07-20 16:27:36.000000000 -0600
+++ work-mm2/drivers/net/irda/w83977af_ir.c	2006-07-20 16:27:35.000000000 -0600
@@ -117,7 +117,7 @@
 
 	IRDA_DEBUG(0, "%s()\n", __FUNCTION__ );
 
-	for (i=0; (io[i] < 2000) && (i < 4); i++) { 
+	for (i=0; (io[i] < 2000) && (i < ARRAY_SIZE(dev_self)); i++) {
 		if (w83977af_open(i, io[i], irq[i], dma[i]) == 0)
 			return 0;
 	}
@@ -136,7 +136,7 @@
 
         IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
 
-	for (i=0; i < 4; i++) {
+	for (i=0; i < ARRAY_SIZE(dev_self); i++) {
 		if (dev_self[i])
 			w83977af_close(dev_self[i]);
 	}
Index: work-mm2/drivers/net/irda/via-ircc.c
===================================================================
--- work-mm2.orig/drivers/net/irda/via-ircc.c	2006-07-25 16:04:03.000000000 -0600
+++ work-mm2/drivers/net/irda/via-ircc.c	2006-07-25 16:04:13.000000000 -0600
@@ -279,7 +279,7 @@
 
 	IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
 
-	for (i=0; i < 4; i++) {
+	for (i=0; i < ARRAY_SIZE(dev_self); i++) {
 		if (dev_self[i])
 			via_ircc_close(dev_self[i]);
 	}
@@ -327,6 +327,9 @@
 
 	IRDA_DEBUG(3, "%s()\n", __FUNCTION__);
 
+	if (i >= ARRAY_SIZE(dev_self))
+		return -ENOMEM;
+
 	/* Allocate new instance of the driver */
 	dev = alloc_irdadev(sizeof(struct via_ircc_cb));
 	if (dev == NULL) 
Index: work-mm2/drivers/net/irda/ali-ircc.c
===================================================================
--- work-mm2.orig/drivers/net/irda/ali-ircc.c	2006-07-25 16:04:03.000000000 -0600
+++ work-mm2/drivers/net/irda/ali-ircc.c	2006-07-25 16:04:30.000000000 -0600
@@ -249,7 +249,7 @@
 
 	IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);	
 
-	for (i=0; i < 4; i++) {
+	for (i=0; i < ARRAY_SIZE(dev_self); i++) {
 		if (dev_self[i])
 			ali_ircc_close(dev_self[i]);
 	}
@@ -273,6 +273,12 @@
 	int err;
 			
 	IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);	
+
+	if (i >= ARRAY_SIZE(dev_self)) {
+		IRDA_ERROR("%s(), maximum number of supported chips reached!\n",
+			   __FUNCTION__);
+		return -ENOMEM;
+	}
 	
 	/* Set FIR FIFO and DMA Threshold */
 	if ((ali_ircc_setup(info)) == -1)
Index: work-mm2/drivers/net/irda/irport.c
===================================================================
--- work-mm2.orig/drivers/net/irda/irport.c	2006-07-25 16:04:03.000000000 -0600
+++ work-mm2/drivers/net/irda/irport.c	2006-07-25 16:04:27.000000000 -0600
@@ -1090,7 +1090,7 @@
 {
  	int i;
 
- 	for (i=0; (io[i] < 2000) && (i < 4); i++) {
+ 	for (i=0; (io[i] < 2000) && (i < ARRAY_SIZE(dev_self)); i++) {
  		if (irport_open(i, io[i], irq[i]) != NULL)
  			return 0;
  	}
@@ -1112,7 +1112,7 @@
 
         IRDA_DEBUG( 4, "%s()\n", __FUNCTION__);
 
-	for (i=0; i < 4; i++) {
+	for (i=0; i < ARRAY_SIZE(dev_self); i++) {
  		if (dev_self[i])
  			irport_close(dev_self[i]);
  	}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ