Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Jun 2000 23:12:45 +0200 (CEST)
From:      adrian@freebsd.org
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   kern/19535: procfs_rlimit tidyup
Message-ID:  <200006262112.XAA00364@vader.creative.net.au>

next in thread | raw e-mail | index | archive | help

>Number:         19535
>Category:       kern
>Synopsis:       procfs_rlimit tidyup
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>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:
>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:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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