[svn-commits] kpfleming: branch 1.4 r3281 - in /branches/1.4: ./ wct4xxp/ wctdm24xxp/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Dec 4 08:48:24 CST 2007


Author: kpfleming
Date: Tue Dec  4 08:48:23 2007
New Revision: 3281

URL: http://svn.digium.com/view/zaptel?view=rev&rev=3281
Log:
use a buffer for the span's device type instead of a string pointer, so each spans can have dynamically set device types instead of constant strings

also fix up some string creation and copying to be safe against buffer overflows

Modified:
    branches/1.4/tor2.c
    branches/1.4/torisa.c
    branches/1.4/wcfxo.c
    branches/1.4/wct1xxp.c
    branches/1.4/wct4xxp/base.c
    branches/1.4/wctdm.c
    branches/1.4/wctdm24xxp/base.c
    branches/1.4/wcte11xp.c
    branches/1.4/wcte12xp.c
    branches/1.4/wcusb.c
    branches/1.4/zaptel-base.c
    branches/1.4/zaptel.h
    branches/1.4/ztdummy.c

Modified: branches/1.4/tor2.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/tor2.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/tor2.c (original)
+++ branches/1.4/tor2.c Tue Dec  4 08:48:23 2007
@@ -270,10 +270,13 @@
 	int x, y, c;
 	for (x = 0; x < SPANS_PER_CARD; x++) {
 		sprintf(tor->spans[x].name, "Tor2/%d/%d", tor->num, x + 1);
-		sprintf(tor->spans[x].desc, "Tormenta 2 (PCI) Quad %s Card %d Span %d", (tor->cardtype == TYPE_T1)  ?  "T1"  :  "E1", tor->num, x + 1);
+		snprintf(tor->spans[x].desc, sizeof(tor->spans[x].desc) - 1,
+			 "Tormenta 2 (PCI) fQuad %s Card %d Span %d",
+			 (tor->cardtype == TYPE_T1)  ?  "T1"  :  "E1", tor->num, x + 1);
 		tor->spans[x].manufacturer = "Digium";
-		tor->spans[x].devicetype = tor->type;
-		sprintf(tor->spans[x].location, "PCI Bus %02d Slot %02d", tor->pci->bus->number, PCI_SLOT(tor->pci->devfn) + 1);
+		strncpy(tor->spans[x].devicetype, tor->type, sizeof(tor->spans[x].devicetype) - 1);
+		snprintf(tor->spans[x].location, sizeof(tor->spans[x].location) - 1,
+			 "PCI Bus %02d Slot %02d", tor->pci->bus->number, PCI_SLOT(tor->pci->devfn) + 1);
 		tor->spans[x].spanconfig = tor2_spanconfig;
 		tor->spans[x].chanconfig = tor2_chanconfig;
 		tor->spans[x].startup = tor2_startup;

Modified: branches/1.4/torisa.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/torisa.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/torisa.c (original)
+++ branches/1.4/torisa.c Tue Dec  4 08:48:23 2007
@@ -1079,9 +1079,9 @@
 	}
 
 	strcpy(spans[0].name, "TorISA/1");
-	strcpy(spans[0].desc, "ISA Tormenta Span 1");
+	strncpy(spans[0].desc, "ISA Tormenta Span 1", sizeof(spans[0].desc) - 1);
 	spans[0].manufacturer = "Digium";
-	spans[0].devicetype = "Tormenta ISA";
+	strncpy(spans[0].devicetype, "Tormenta ISA", sizeof(spans[0].devicetype) - 1);
 	spans[0].spanconfig = torisa_spanconfig;
 	spans[0].chanconfig = torisa_chanconfig;
 	spans[0].startup = torisa_startup;

Modified: branches/1.4/wcfxo.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/wcfxo.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/wcfxo.c (original)
+++ branches/1.4/wcfxo.c Tue Dec  4 08:48:23 2007
@@ -625,11 +625,12 @@
 {
 	/* Zapata stuff */
 	sprintf(wc->span.name, "WCFXO/%d", wc->pos);
-	sprintf(wc->span.desc, "%s Board %d", wc->variety, wc->pos + 1);
+	snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Board %d", wc->variety, wc->pos + 1);
 	sprintf(wc->chan.name, "WCFXO/%d/%d", wc->pos, 0);
-	sprintf(wc->span.location, "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
+	snprintf(wc->span.location, sizeof(wc->span.location) - 1,
+		 "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
 	wc->span.manufacturer = "Digium";
-	wc->span.devicetype = wc->variety;
+	strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1);
 	wc->chan.sigcap = ZT_SIG_FXSKS | ZT_SIG_FXSLS | ZT_SIG_SF;
 	wc->chan.chanpos = 1;
 	wc->span.chans = &wc->chan;

Modified: branches/1.4/wct1xxp.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/wct1xxp.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/wct1xxp.c (original)
+++ branches/1.4/wct1xxp.c Tue Dec  4 08:48:23 2007
@@ -761,10 +761,11 @@
 		return -1;
 	wc->num = x;
 	sprintf(wc->span.name, "WCT1/%d", wc->num);
-	sprintf(wc->span.desc, "%s Card %d", wc->variety, wc->num);
+	snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Card %d", wc->variety, wc->num);
 	wc->span.manufacturer = "Digium";
-	wc->span.devicetype = wc->variety;
-	sprintf(wc->span.location, "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
+	strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1);
+	snprintf(wc->span.location, sizeof(wc->span.location) - 1,
+		 "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
 	wc->span.spanconfig = t1xxp_spanconfig;
 	wc->span.chanconfig = t1xxp_chanconfig;
 	wc->span.irq = wc->dev->irq;

Modified: branches/1.4/wct4xxp/base.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/wct4xxp/base.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/wct4xxp/base.c (original)
+++ branches/1.4/wct4xxp/base.c Tue Dec  4 08:48:23 2007
@@ -1530,10 +1530,13 @@
 	for (x = 0; x < wc->numspans; x++) {
 		ts = wc->tspans[x];
 		sprintf(ts->span.name, "TE%d/%d/%d", wc->numspans, wc->num, x + 1);
-		sprintf(ts->span.desc, "T%dXXP (PCI) Card %d Span %d", wc->numspans, wc->num, x+1);
+		snprintf(ts->span.desc, sizeof(ts->span.desc) - 1,
+			 "T%dXXP (PCI) Card %d Span %d", wc->numspans, wc->num, x+1);
 		ts->span.manufacturer = "Digium";
-		ts->span.devicetype = wc->variety;
-		sprintf(ts->span.location, "PCI%sBus %02d Slot %02d", ts->spanflags & FLAG_EXPRESS ? " Express" : " ", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
+		strncpy(ts->span.devicetype, wc->variety, sizeof(ts->span.devicetype) - 1);
+		snprintf(ts->span.location, sizeof(ts->span.location) - 1,
+			 "PCI%sBus %02d Slot %02d", ts->spanflags & FLAG_EXPRESS ? " Express" : " ",
+			 wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
 		switch (ts->spantype) {
 		case TYPE_T1:
 			ts->span.spantype = "T1";

Modified: branches/1.4/wctdm.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/wctdm.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/wctdm.c (original)
+++ branches/1.4/wctdm.c Tue Dec  4 08:48:23 2007
@@ -2022,10 +2022,11 @@
 
 	/* Zapata stuff */
 	sprintf(wc->span.name, "WCTDM/%d", wc->pos);
-	sprintf(wc->span.desc, "%s Board %d", wc->variety, wc->pos + 1);
-	sprintf(wc->span.location, "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
+	snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Board %d", wc->variety, wc->pos + 1);
+	snprintf(wc->span.location, sizeof(wc->span.location) - 1,
+		 "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
 	wc->span.manufacturer = "Digium";
-	wc->span.devicetype = wc->variety;
+	strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1);
 	if (alawoverride) {
 		printk("ALAW override parameter detected.  Device will be operating in ALAW\n");
 		wc->span.deflaw = ZT_LAW_ALAW;

Modified: branches/1.4/wctdm24xxp/base.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/wctdm24xxp/base.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/wctdm24xxp/base.c (original)
+++ branches/1.4/wctdm24xxp/base.c Tue Dec  4 08:48:23 2007
@@ -3045,10 +3045,12 @@
 
 	/* Zapata stuff */
 	sprintf(wc->span.name, "WCTDM/%d", wc->pos);
-	sprintf(wc->span.desc, "%s Board %d", wc->variety, wc->pos + 1);
-	sprintf(wc->span.location, "PCI%s Bus %02d Slot %02d", (wc->flags[0] & FLAG_EXPRESS) ? " Express" : "", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
+	snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Board %d", wc->variety, wc->pos + 1);
+	snprintf(wc->span.location, sizeof(wc->span.location) - 1,
+		 "PCI%s Bus %02d Slot %02d", (wc->flags[0] & FLAG_EXPRESS) ? " Express" : "",
+		 wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
 	wc->span.manufacturer = "Digium";
-	wc->span.devicetype = wc->variety;
+	strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1);
 	if (alawoverride) {
 		printk("ALAW override parameter detected.  Device will be operating in ALAW\n");
 		wc->span.deflaw = ZT_LAW_ALAW;

Modified: branches/1.4/wcte11xp.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/wcte11xp.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/wcte11xp.c (original)
+++ branches/1.4/wcte11xp.c Tue Dec  4 08:48:23 2007
@@ -971,10 +971,11 @@
 	t4_serial_setup(wc);
 	wc->num = x;
 	sprintf(wc->span.name, "WCT1/%d", wc->num);
-	sprintf(wc->span.desc, "%s Card %d", wc->variety, wc->num);
+	snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Card %d", wc->variety, wc->num);
 	wc->span.manufacturer = "Digium";
-	wc->span.devicetype = wc->variety;
-	sprintf(wc->span.location, "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
+	strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1);
+	snprintf(wc->span.location, sizeof(wc->span.location) - 1,
+		 "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
 	wc->span.spanconfig = t1xxp_spanconfig;
 	wc->span.chanconfig = t1xxp_chanconfig;
 	wc->span.irq = wc->dev->irq;

Modified: branches/1.4/wcte12xp.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/wcte12xp.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/wcte12xp.c (original)
+++ branches/1.4/wcte12xp.c Tue Dec  4 08:48:23 2007
@@ -1352,10 +1352,11 @@
 
 	wc->num = x;
 	sprintf(wc->span.name, "WCT1/%d", wc->num);
-	sprintf(wc->span.desc, "%s Card %d", wc->variety, wc->num);
+	snprintf(wc->span.desc, sizeof(wc->span.desc) - 1, "%s Card %d", wc->variety, wc->num);
 	wc->span.manufacturer = "Digium";
-	wc->span.devicetype = wc->variety;
-	sprintf(wc->span.location, "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
+	strncpy(wc->span.devicetype, wc->variety, sizeof(wc->span.devicetype) - 1);
+	snprintf(wc->span.location, sizeof(wc->span.location) - 1,
+		 "PCI Bus %02d Slot %02d", wc->dev->bus->number, PCI_SLOT(wc->dev->devfn) + 1);
 
 	wc->span.spanconfig = t1xxp_spanconfig;
 	wc->span.chanconfig = t1xxp_chanconfig;

Modified: branches/1.4/wcusb.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/wcusb.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/wcusb.c (original)
+++ branches/1.4/wcusb.c Tue Dec  4 08:48:23 2007
@@ -1248,10 +1248,10 @@
 	}
 
 	sprintf(p->span.name, "WCUSB/%d", x);
-	sprintf(p->span.desc,"%s %d", p->span.name, x);
+	snprintf(p->span.desc, sizeof(p->span.desc) - 1, "%s %d", p->span.name, x);
         sprintf(p->chan.name, "WCUSB/%d/%d", x, 0);
 	p->span.manufacturer = "Digium";
-	p->span.devicetype = p->variety;
+	strncpy(p->span.devicetype, p->variety, sizeof(p->span.devicetype) - 1);
 
         p->chan.sigcap = ZT_SIG_FXOKS | ZT_SIG_FXOLS | ZT_SIG_FXOGS;    /* We're capabable of both FXOKS and FXOLS */
         p->chan.chanpos = 1;

Modified: branches/1.4/zaptel-base.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/zaptel-base.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/zaptel-base.c (original)
+++ branches/1.4/zaptel-base.c Tue Dec  4 08:48:23 2007
@@ -3177,12 +3177,13 @@
 		stack.spaninfo.linecompat = spans[i]->linecompat;
 		strncpy(stack.spaninfo.lboname, zt_lboname(spans[i]->lbo), sizeof(stack.spaninfo.lboname) - 1);
 		if (spans[i]->manufacturer)
-			strncpy(stack.spaninfo.manufacturer, spans[i]->manufacturer, sizeof(stack.spaninfo.manufacturer));
+			strncpy(stack.spaninfo.manufacturer, spans[i]->manufacturer,
+				sizeof(stack.spaninfo.manufacturer) - 1);
 		if (spans[i]->devicetype)
-			strncpy(stack.spaninfo.devicetype, spans[i]->devicetype, sizeof(stack.spaninfo.devicetype));
-		strncpy(stack.spaninfo.location, spans[i]->location, sizeof(stack.spaninfo.location));
+			strncpy(stack.spaninfo.devicetype, spans[i]->devicetype, sizeof(stack.spaninfo.devicetype) - 1);
+		strncpy(stack.spaninfo.location, spans[i]->location, sizeof(stack.spaninfo.location) - 1);
 		if (spans[i]->spantype)
-			strncpy(stack.spaninfo.spantype, spans[i]->spantype, sizeof(stack.spaninfo.spantype));
+			strncpy(stack.spaninfo.spantype, spans[i]->spantype, sizeof(stack.spaninfo.spantype) - 1);
 		
 		if (copy_to_user((struct zt_spaninfo *) data, &stack.spaninfo, size_to_copy))
 			return -EFAULT;

Modified: branches/1.4/zaptel.h
URL: http://svn.digium.com/view/zaptel/branches/1.4/zaptel.h?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/zaptel.h (original)
+++ branches/1.4/zaptel.h Tue Dec  4 08:48:23 2007
@@ -1420,7 +1420,7 @@
 	char desc[80];			/* Span description */
 	const char *spantype;		/* span type in text form */
 	const char *manufacturer;	/* span's device manufacturer */
-	const char *devicetype;		/* span's device type */
+	char devicetype[80];		/* span's device type */
 	char location[40];		/* span device's location in system */
 	int deflaw;			/* Default law (ZT_MULAW or ZT_ALAW) */
 	int alarms;			/* Pending alarms on span */

Modified: branches/1.4/ztdummy.c
URL: http://svn.digium.com/view/zaptel/branches/1.4/ztdummy.c?view=diff&rev=3281&r1=3280&r2=3281
==============================================================================
--- branches/1.4/ztdummy.c (original)
+++ branches/1.4/ztdummy.c Tue Dec  4 08:48:23 2007
@@ -260,9 +260,9 @@
 {
 	/* Zapata stuff */
 	sprintf(ztd->span.name, "ZTDUMMY/1");
-	sprintf(ztd->span.desc, "%s (source: " CLOCK_SRC ") %d", ztd->span.name, 1);
+	snprintf(ztd->span.desc, sizeof(ztd->span.desc) - 1, "%s (source: " CLOCK_SRC ") %d", ztd->span.name, 1);
 	sprintf(ztd->chan.name, "ZTDUMMY/%d/%d", 1, 0);
-	ztd->span.devicetype = "Zaptel Dummy Timing Driver";
+	strncpy(ztd->span.devicetype, "Zaptel Dummy Timing Driver", sizeof(ztd->span.devicetype) - 1);
 	ztd->chan.chanpos = 1;
 	ztd->span.chans = &ztd->chan;
 	ztd->span.channels = 0;		/* no channels on our span */




More information about the svn-commits mailing list