summaryrefslogtreecommitdiffstats
path: root/usr.bin/pathchk
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-05-01 22:00:28 +0000
committerjilles <jilles@FreeBSD.org>2010-05-01 22:00:28 +0000
commitb1c9a3a8211c0dc64b4ed5f2b5da177736dff1ae (patch)
tree9ad8f6ef7445422f5f2af34201004d88964d4b9f /usr.bin/pathchk
parent01a827bd910a0e0a956fa132ab9ab657527ec788 (diff)
downloadFreeBSD-src-b1c9a3a8211c0dc64b4ed5f2b5da177736dff1ae.zip
FreeBSD-src-b1c9a3a8211c0dc64b4ed5f2b5da177736dff1ae.tar.gz
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. MFC after: 1 week
Diffstat (limited to 'usr.bin/pathchk')
-rw-r--r--usr.bin/pathchk/pathchk.114
-rw-r--r--usr.bin/pathchk/pathchk.c18
2 files changed, 26 insertions, 6 deletions
diff --git a/usr.bin/pathchk/pathchk.1 b/usr.bin/pathchk/pathchk.1
index e863955..fb50e84 100644
--- a/usr.bin/pathchk/pathchk.1
+++ b/usr.bin/pathchk/pathchk.1
@@ -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
diff --git a/usr.bin/pathchk/pathchk.c b/usr.bin/pathchk/pathchk.c
index dd9768a..2d8fa59 100644
--- a/usr.bin/pathchk/pathchk.c
+++ b/usr.bin/pathchk/pathchk.c
@@ -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]);
OpenPOWER on IntegriCloud