Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Sep 2001 02:58:43 -0400
From:      Mike Barcroft <mike@FreeBSD.org>
To:        audit@FreeBSD.org
Cc:        Dag-Erling Smorgrav <des@ofug.org>
Subject:   procfs change for review
Message-ID:  <20010910025843.A18719@coffee.q9media.com>

next in thread | raw e-mail | index | archive | help
I would appreciate reviews on the following change to procfs.  The
problem this patch corrects can be observed by doing the following:

% cp /bin/cat c\ a\ t
% ./c\ a\ t /proc/curproc/status

Current procfs:
c a t 21589 20303 21589 20303 12,4 ctty 1000103493,166578 0,0 0,4185 nochan 1000 1000 1000,1000,1000,0 -

Procfs (with patch applied):
c\040a\040t 22970 20303 22970 20303 12,4 ctty 1000103759,393406 0,0 0,3960 nochan 1000 1000 1000,1000,1000,0 -

Since the first version contains spaces, a script parsing the data will
become confused and fail.

The patch is at the end of this e-mail and also available at:
http://people.FreeBSD.org/~mike/patches/procfs.20010824.patch

Best regards,
Mike Barcroft

----------------------------------------------------------------------

procfs.20010824.patch

A process name may contain whitespace and unprintable characters,
so convert those characters to octal notation.  Also convert
backslashes to octal notation to avoid confusion.

Index: procfs_status.c
===================================================================
RCS file: /home/ncvs/src/sys/fs/procfs/procfs_status.c,v
retrieving revision 1.32
diff -u -r1.32 procfs_status.c
--- procfs_status.c	2001/07/05 17:10:43	1.32
+++ procfs_status.c	2001/08/25 01:07:42
@@ -69,7 +69,7 @@
 	struct session *sess;
 	struct tty *tp;
 	struct ucred *cr;
-	char *ps;
+	char *ps, *pc;
 	char *sep;
 	int pid, ppid, pgid, sid;
 	int i;
@@ -95,10 +95,16 @@
 			("Too short buffer for new MAXCOMLEN"));
 
 	ps = psbuf;
-	bcopy(p->p_comm, ps, MAXCOMLEN);
-	ps[MAXCOMLEN] = '\0';
-	ps += strlen(ps);
-	DOCHECK();
+	pc = p->p_comm;
+	xlen = strlen(p->p_comm);
+	do {
+		if (*pc < 33 || *pc > 126 || *pc == 92)
+			ps += snprintf(ps, psbuf + sizeof(psbuf) - ps, "\\%03o",
+			    *pc);
+		else
+			*ps++ = *pc;
+		DOCHECK();
+	} while (++pc < p->p_comm + xlen);
 	ps += snprintf(ps, psbuf + sizeof(psbuf) - ps,
 	    " %d %d %d %d ", pid, ppid, pgid, sid);
 	DOCHECK();

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




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