From randy@sierra.zyzzyva.com  Mon May 12 11:54:05 1997
Received: from sierra.zyzzyva.com (ppp01-58.zyzzyva.com [208.214.58.10])
          by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id LAA27806
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 12 May 1997 11:54:01 -0700 (PDT)
Received: (from randy@localhost) by sierra.zyzzyva.com (8.8.5/8.8.2) id NAA11137; Mon, 12 May 1997 13:52:40 -0500 (CDT)
Message-Id: <199705121852.NAA11137@sierra.zyzzyva.com>
Date: Mon, 12 May 1997 13:52:40 -0500 (CDT)
From: randy@zyzzyva.com
Reply-To: randy@zyzzyva.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: 'sysctl kern' dumps core when displaying clockrate
X-Send-Pr-Version: 3.2

>Number:         3583
>Category:       kern
>Synopsis:       'syctl kern' dumps core when displaying clockrate
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 12 12:00:01 PDT 1997
>Closed-Date:    Sat May 30 13:08:16 PDT 1998
>Last-Modified:  Sat May 30 13:08:56 PDT 1998
>Originator:     Randy Terbush
>Release:        FreeBSD 2.2-STABLE i386
>Organization:
>Environment:

	64MB RAM
	Pentium 133P5

	The following possibly relevent kernel parameter tweaks:

	maxusers        256
	options         NMBCLUSTERS=4096
	options         DFLDSIZ=33554432
	options         DFLSSIZ=1048576
	options         CHILD_MAX=1536
	options         OPEN_MAX=1536


>Description:

	sysctl kern works fine within the first few minutes after a reboot.
	Soon, it begins dumping core when attempting to print/retreive 
	kern.clockrate. I've reported this in the past, but I cannot find it 
	in the gnats DB. It is possible that it was mistakenly closed when I 
	thought it had been fixed since it works right after rebooting.

>How-To-Repeat:



>Fix:
	
	I'm not sure if this is the correct fix, or if perhaps the clockrate is
	being stored without \0 termination and is causing the memory requirement
	in show_var() to be unecessarily large.



Index: sysctl.c
===================================================================
RCS file: /usr/local/src/FreeBSD/FreeBSD-CVS/src/usr.sbin/sysctl/sysctl.c,v
retrieving revision 1.10
diff -c -r1.10 sysctl.c
*** sysctl.c	1996/04/10 00:53:22	1.10
--- sysctl.c	1997/05/11 16:47:39
***************
*** 341,349 ****
  
  	/* find an estimate of how much we need for this var */
  	j = 0;
! 	i = sysctl(oid, nlen, 0, &j, 0, 0);
! 	j += j; /* we want to be sure :-) */
! 
  	val = alloca(j);
  	len = j;
  	i = sysctl(oid, nlen, val, &len, 0, 0);
--- 341,347 ----
  
  	/* find an estimate of how much we need for this var */
  	j = 0;
! 	i = sysctl(oid, nlen, NULL, &j, 0, 0);
  	val = alloca(j);
  	len = j;
  	i = sysctl(oid, nlen, val, &len, 0, 0);

>Release-Note:
>Audit-Trail:

From: David Greenman <dg@root.com>
To: randy@zyzzyva.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, phk@FreeBSD.ORG
Subject: Re: kern/3583: 'sysctl kern' dumps core when displaying clockrate 
Date: Mon, 12 May 1997 20:30:16 -0700

 >	sysctl kern works fine within the first few minutes after a reboot.
 >	Soon, it begins dumping core when attempting to print/retreive 
 >	kern.clockrate. I've reported this in the past, but I cannot find it 
 >	in the gnats DB. It is possible that it was mistakenly closed when I 
 >	thought it had been fixed since it works right after rebooting.
 
 >! 	i = sysctl(oid, nlen, 0, &j, 0, 0);
 >! 	j += j; /* we want to be sure :-) */
 >! 
 >  	val = alloca(j);
 >  	len = j;
 >  	i = sysctl(oid, nlen, val, &len, 0, 0);
 >--- 341,347 ----
 >  
 >  	/* find an estimate of how much we need for this var */
 >  	j = 0;
 >! 	i = sysctl(oid, nlen, NULL, &j, 0, 0);
 >  	val = alloca(j);
 >  	len = j;
 
    The problem is caused by the proc structs being too large to fit on
 your stack - thus causing an rlimit violation. This is actually an
 architectural flaw in the sysctl mechanism since the information returned
 from reading the struct procs is actually later discarded. The code needs
 to be re-written to only retrieve sysctl variables that are actually needed.
 You can temporarily work around the problem by increasing your stack rlimit
 to something larger than 8MB.
 
 -DG
 
 David Greenman
 Core-team/Principal Architect, The FreeBSD Project
State-Changed-From-To: open->feedback 
State-Changed-By: phk 
State-Changed-When: Sun Apr 12 04:35:39 PDT 1998 
State-Changed-Why:  
is this still a problem ? 
State-Changed-From-To: feedback->closed 
State-Changed-By: steve 
State-Changed-When: Sat May 30 13:08:16 PDT 1998 
State-Changed-Why:  
Originator noted this has been fixed in both 2.2.6 and -current. 
>Unformatted:
