From owner-svn-src-all@FreeBSD.ORG Sat Jan 17 15:56:39 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6AB5E106566B; Sat, 17 Jan 2009 15:56:39 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3E1C68FC0A; Sat, 17 Jan 2009 15:56:39 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n0HFud2A046719; Sat, 17 Jan 2009 15:56:39 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n0HFudKj046718; Sat, 17 Jan 2009 15:56:39 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200901171556.n0HFudKj046718@svn.freebsd.org> From: Ed Schouten Date: Sat, 17 Jan 2009 15:56:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r187366 - head/libexec/comsat X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jan 2009 15:56:39 -0000 Author: ed Date: Sat Jan 17 15:56:38 2009 New Revision: 187366 URL: http://svn.freebsd.org/changeset/base/187366 Log: Fix handling of pts(4) device names in comsat(8). Also catch fork() errors. Pseudo-terminals allocated with posix_openpt(2) will have more slashes in their path names than comsat(8) allows, so allow slashes when the character device name starts with "pts/". This patch is loosely based on NetBSD's changes, revision 1.33. Because it also included the changes to fork(), I imported them here as well. Maybe we could import even more fixes from the other BSD's? Original commit message from the NetBSD folks: PR/30170: Markus W Kilbinger: src/libexec/comsat complains about: '/' in "/dev/pts/1" Reported by: Robert Huff Modified: head/libexec/comsat/comsat.c Modified: head/libexec/comsat/comsat.c ============================================================================== --- head/libexec/comsat/comsat.c Sat Jan 17 14:52:26 2009 (r187365) +++ head/libexec/comsat/comsat.c Sat Jan 17 15:56:38 2009 (r187366) @@ -203,21 +203,32 @@ notify(struct utmp *utp, char file[], of struct stat stb; struct termios tio; char tty[20], name[sizeof(utmp[0].ut_name) + 1]; + const char *cr = utp->ut_line; - (void)snprintf(tty, sizeof(tty), "%s%.*s", - _PATH_DEV, (int)sizeof(utp->ut_line), utp->ut_line); - if (strchr(tty + sizeof(_PATH_DEV) - 1, '/')) { + if (strncmp(cr, "pts/", 4) == 0) + cr += 4; + if (strchr(cr, '/')) { /* A slash is an attempt to break security... */ - syslog(LOG_AUTH | LOG_NOTICE, "'/' in \"%s\"", tty); + syslog(LOG_AUTH | LOG_NOTICE, "Unexpected `/' in `%s'", + utp->ut_line); return; } - if (stat(tty, &stb) || !(stb.st_mode & (S_IXUSR | S_IXGRP))) { + (void)snprintf(tty, sizeof(tty), "%s%.*s", + _PATH_DEV, (int)sizeof(utp->ut_line), utp->ut_line); + if (stat(tty, &stb) == -1 || !(stb.st_mode & (S_IXUSR | S_IXGRP))) { dsyslog(LOG_DEBUG, "%s: wrong mode on %s", utp->ut_name, tty); return; } dsyslog(LOG_DEBUG, "notify %s on %s\n", utp->ut_name, tty); - if (fork()) + switch (fork()) { + case -1: + syslog(LOG_NOTICE, "fork failed (%m)"); return; + case 0: + break; + default: + return; + } (void)signal(SIGALRM, SIG_DFL); (void)alarm((u_int)30); if ((tp = fopen(tty, "w")) == NULL) {