From adrian@vader.creative.net.au  Mon Jun 26 14:13:18 2000
Return-Path: <adrian@vader.creative.net.au>
Received: from vader.creative.net.au (vader.creative.net.au [203.56.168.35])
	by hub.freebsd.org (Postfix) with ESMTP id CB2D637B7B4
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 26 Jun 2000 14:12:59 -0700 (PDT)
	(envelope-from adrian@vader.creative.net.au)
Received: (from adrian@localhost)
	by vader.creative.net.au (8.9.3/8.9.3) id XAA00364;
	Mon, 26 Jun 2000 23:12:45 +0200 (CEST)
	(envelope-from adrian)
Message-Id: <200006262112.XAA00364@vader.creative.net.au>
Date: Mon, 26 Jun 2000 23:12:45 +0200 (CEST)
From: adrian@freebsd.org
Sender: adrian@vader.creative.net.au
Reply-To: adrian@vader.creative.net.au
To: FreeBSD-gnats-submit@freebsd.org
Subject: procfs_rlimit tidyup
X-Send-Pr-Version: 3.2

>Number:         19535
>Category:       kern
>Synopsis:       [procfs] [patch] procfs_rlimit tidyup
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          suspended
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 26 14:20:01 PDT 2000
>Closed-Date:    
>Last-Modified:  Mon Oct 24 02:16:19 GMT 2005
>Originator:     Adrian Chadd
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
>Environment:

FreeBSD vader.creative.net.au 5.0-CURRENT FreeBSD 5.0-CURRENT #6: Mon Jun 26 22:54:29 CEST 2000     adrian@vader.creative.net.au:/usr/src/sys/compile/VADER  i386

>Description:

A quick tidyup of procfs_rlimit.c. Specifically, making the code a little
more style(9) compliant, and taking out a char[512] which is bad juju
in kernel code.

>How-To-Repeat:

N/A

>Fix:

Apply this patch:

Index: procfs_rlimit.c
===================================================================
RCS file: /home/ncvs/src/sys/miscfs/procfs/procfs_rlimit.c,v
retrieving revision 1.5
diff -u -r1.5 procfs_rlimit.c
--- procfs_rlimit.c	1999/12/08 08:59:37	1.5
+++ procfs_rlimit.c	2000/06/26 21:10:33
@@ -52,6 +52,7 @@
 #include <sys/resourcevar.h>
 #include <sys/resource.h>
 #include <sys/types.h>
+#include <sys/malloc.h>
 #include <miscfs/procfs/procfs.h>
 
 
@@ -66,41 +67,25 @@
 	int i;
 	int xlen;
 	int error;
-	char psbuf[512];		/* XXX - conservative */
+	char *psbuf;
 
 	if (uio->uio_rw != UIO_READ)
 		return (EOPNOTSUPP);
-
-
+	psbuf = (char *)malloc(512 * sizeof(char), M_TEMP, M_WAITOK);
+		/* XXX conservative, but potentially overflowable */
 	ps = psbuf;
-
 	for (i = 0; i < RLIM_NLIMITS; i++) {
-
-		/*
-		 * Add the rlimit ident
-		 */
-
+		/* Add the rlimit ident */
 		ps += sprintf(ps, "%s ", rlimit_ident[i]);
-
-		/* 
-		 * Replace RLIM_INFINITY with -1 in the string
-		 */
-
-		/*
-		 * current limit
-		 */
-
+		/* Replace RLIM_INFINITY with -1 in the string */
+		/* current limit */
 		if (p->p_rlimit[i].rlim_cur == RLIM_INFINITY) {
 			ps += sprintf(ps, "-1 ");
 		} else {
 			ps += sprintf(ps, "%llu ",
 				(unsigned long long)p->p_rlimit[i].rlim_cur);
 		}
-
-		/*
-		 * maximum limit
-		 */
-
+		/* maximum limit */
 		if (p->p_rlimit[i].rlim_max == RLIM_INFINITY) {
 			ps += sprintf(ps, "-1\n");
 		} else {
@@ -108,12 +93,10 @@
 				(unsigned long long)p->p_rlimit[i].rlim_max);
 		}
 	}
-
 	/*
 	 * This logic is rather tasty - but its from procfs_status.c, so
 	 * I guess I'll use it here.
 	 */
-
 	xlen = ps - psbuf;
 	xlen -= uio->uio_offset;
 	ps = psbuf + uio->uio_offset;
@@ -122,7 +105,7 @@
 		error = 0;
 	else
 		error = uiomove(ps, xlen, uio);
-
+	free(psbuf, M_TEMP);
 	return (error);
 }
 


>Release-Note:
>Audit-Trail:

From: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To: adrian@vader.creative.net.au
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: kern/19535: procfs_rlimit tidyup
Date: Tue, 27 Jun 2000 11:29:22 -0400 (EDT)

 <<On Mon, 26 Jun 2000 23:12:45 +0200 (CEST), adrian@FreeBSD.ORG said:
 
 > +	psbuf = (char *)malloc(512 * sizeof(char), M_TEMP, M_WAITOK);
 
 sizeof(char) is defined to be 1.
 
 > +		/* XXX conservative, but potentially overflowable */
 
 It should be possible to compute the exact buffer size.  Since this
 code is not frequently run, I would suggest that a two-pass approach
 would not hurt.
 
 
 -GAWollman
 
 

From: Adrian Chadd <adrian@freebsd.org>
To: Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: kern/19535: procfs_rlimit tidyup
Date: Tue, 27 Jun 2000 17:49:22 +0200

 On Tue, Jun 27, 2000, Garrett Wollman wrote:
 > <<On Mon, 26 Jun 2000 23:12:45 +0200 (CEST), adrian@FreeBSD.ORG said:
 > 
 > > +	psbuf = (char *)malloc(512 * sizeof(char), M_TEMP, M_WAITOK);
 > 
 > sizeof(char) is defined to be 1.
 
 Being pedantic.
 
 > > +		/* XXX conservative, but potentially overflowable */
 > 
 > It should be possible to compute the exact buffer size.  Since this
 > code is not frequently run, I would suggest that a two-pass approach
 > would not hurt.
 
 I'm going to go through later on and redo this repeated evilness in
 procfs. I thought I'd submit this change now to get rid of the
 blantant hacks.
 
 
 
 Adrian
 
 -- 
 Adrian Chadd			Build a man a fire, and he's warm for the
 <adrian@FreeBSD.org>		rest of the evening. Set a man on fire and
 				he's warm for the rest of his life.
 
 
Responsible-Changed-From-To: freebsd-bugs->adrian 
Responsible-Changed-By: adrian 
Responsible-Changed-When: Tue Jul 4 00:29:45 PDT 2000 
Responsible-Changed-Why:  
I can commit my own PRs now. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=19535 
Responsible-Changed-From-To: adrian->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Sep 13 05:46:43 GMT 2004 
Responsible-Changed-Why:  
With bugmeister hat on, reassign from recently inactive committer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=19535 
State-Changed-From-To: open->suspended 
State-Changed-By: linimon 
State-Changed-When: Mon Oct 24 02:16:03 GMT 2005 
State-Changed-Why:  
Mark as 'suspended' since this does not seem as though it is being 
actively worked on. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=19535 
>Unformatted:
