From owner-svn-src-stable@FreeBSD.ORG Sun May 9 19:30:52 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CD3751065670; Sun, 9 May 2010 19:30:52 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [69.147.83.44]) by mx1.freebsd.org (Postfix) with ESMTP id BC0E78FC18; Sun, 9 May 2010 19:30:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o49JUq7g025378; Sun, 9 May 2010 19:30:52 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o49JUqoZ025375; Sun, 9 May 2010 19:30:52 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201005091930.o49JUqoZ025375@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 9 May 2010 19:30:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r207826 - stable/8/usr.bin/pathchk X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 May 2010 19:30:52 -0000 Author: jilles Date: Sun May 9 19:30:52 2010 New Revision: 207826 URL: http://svn.freebsd.org/changeset/base/207826 Log: MFC r207483: pathchk: Add the new POSIX -P option. This option checks for empty pathnames and components starting with '-'. Our -p option also checks for the latter, which remains the case. Modified: stable/8/usr.bin/pathchk/pathchk.1 stable/8/usr.bin/pathchk/pathchk.c Directory Properties: stable/8/usr.bin/pathchk/ (props changed) Modified: stable/8/usr.bin/pathchk/pathchk.1 ============================================================================== --- stable/8/usr.bin/pathchk/pathchk.1 Sun May 9 17:15:26 2010 (r207825) +++ stable/8/usr.bin/pathchk/pathchk.1 Sun May 9 19:30:52 2010 (r207826) @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 21, 2002 +.Dd May 1, 2010 .Dt PATHCHK 1 .Os .Sh NAME @@ -35,7 +35,7 @@ .Nd check pathnames .Sh SYNOPSIS .Nm -.Op Fl p +.Op Fl pP .Ar pathname ... .Sh DESCRIPTION The @@ -95,6 +95,16 @@ No component may start with the hyphen .Pq Ql \&- character. .El +.It Fl P +In addition to the default or +.Fl p +checks, write a diagnostic for each argument that: +.Bl -bullet +.It +Is empty. +.It +Contains a component that starts with a hyphen. +.El .El .Sh EXIT STATUS .Ex -std Modified: stable/8/usr.bin/pathchk/pathchk.c ============================================================================== --- stable/8/usr.bin/pathchk/pathchk.c Sun May 9 17:15:26 2010 (r207825) +++ stable/8/usr.bin/pathchk/pathchk.c Sun May 9 19:30:52 2010 (r207826) @@ -51,6 +51,7 @@ static int portable(const char *); static void usage(void); static int pflag; /* Perform portability checks */ +static int Pflag; /* Check for empty paths, leading '-' */ int main(int argc, char *argv[]) @@ -58,11 +59,14 @@ main(int argc, char *argv[]) int ch, rval; const char *arg; - while ((ch = getopt(argc, argv, "p")) > 0) { + while ((ch = getopt(argc, argv, "pP")) > 0) { switch (ch) { case 'p': pflag = 1; break; + case 'P': + Pflag = 1; + break; default: usage(); /*NOTREACHED*/ @@ -102,6 +106,15 @@ check(const char *path) p = pathd; + if (Pflag && *p == '\0') { + warnx("%s: empty pathname", path); + goto bad; + } + if ((Pflag || pflag) && (*p == '-' || strstr(p, "/-") != NULL)) { + warnx("%s: contains a component starting with '-'", path); + goto bad; + } + if (!pflag) { errno = 0; namemax = pathconf(*p == '/' ? "/" : ".", _PC_NAME_MAX); @@ -182,9 +195,6 @@ portable(const char *path) "0123456789._-"; long s; - if (*path == '-') - return (*path); - s = strspn(path, charset); if (path[s] != '\0') return (path[s]);