From owner-freebsd-audit Sun Sep 9 23:55:49 2001 Delivered-To: freebsd-audit@freebsd.org Received: from coffee.q9media.com (coffee.q9media.com [216.94.229.19]) by hub.freebsd.org (Postfix) with ESMTP id 9990837B401 for ; Sun, 9 Sep 2001 23:55:44 -0700 (PDT) Received: (from mike@localhost) by coffee.q9media.com (8.11.2/8.11.3) id f8A6wiW18995; Mon, 10 Sep 2001 02:58:44 -0400 (EDT) (envelope-from mike) Date: Mon, 10 Sep 2001 02:58:43 -0400 From: Mike Barcroft To: audit@FreeBSD.org Cc: Dag-Erling Smorgrav Subject: procfs change for review Message-ID: <20010910025843.A18719@coffee.q9media.com> Mail-Followup-To: Mike Barcroft , audit@FreeBSD.org, Dag-Erling Smorgrav Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Organization: The FreeBSD Project Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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