Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Nov 2009 00:52:14 +0000 (UTC)
From:      Attilio Rao <attilio@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r199209 - head/sys/kern
Message-ID:  <200911120052.nAC0qEjC012881@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: attilio
Date: Thu Nov 12 00:52:14 2009
New Revision: 199209
URL: http://svn.freebsd.org/changeset/base/199209

Log:
  The building the dev nameunit string, in devclass_add_device() is based
  on the assumption that the unit linked with the device is invariant but
  that can change when calling devclass_alloc_unit() (because -1 is passed
  or, more simply, because the unit choosen is beyond the table limits).
  This results in a completely bogus string building.
  
  Fix this by reserving the necessary room for all the possible characters
  printable by a positive integer (we do not allow for negative unit
  number).
  
  Reported by:	Sandvine Incorporated
  Reviewed by:	emaste
  Sponsored by:	Sandvine Incorporated
  MFC:		1 week

Modified:
  head/sys/kern/subr_bus.c

Modified: head/sys/kern/subr_bus.c
==============================================================================
--- head/sys/kern/subr_bus.c	Thu Nov 12 00:46:28 2009	(r199208)
+++ head/sys/kern/subr_bus.c	Thu Nov 12 00:52:14 2009	(r199209)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/lock.h>
 #include <sys/kernel.h>
 #include <sys/kobj.h>
+#include <sys/limits.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
 #include <sys/mutex.h>
@@ -1584,7 +1585,7 @@ devclass_add_device(devclass_t dc, devic
 
 	PDEBUG(("%s in devclass %s", DEVICENAME(dev), DEVCLANAME(dc)));
 
-	buflen = snprintf(NULL, 0, "%s%d$", dc->name, dev->unit);
+	buflen = snprintf(NULL, 0, "%s%d$", dc->name, INT_MAX);
 	if (buflen < 0)
 		return (ENOMEM);
 	dev->nameunit = malloc(buflen, M_BUS, M_NOWAIT|M_ZERO);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200911120052.nAC0qEjC012881>