diff options
author | Roland Mainz <roland.mainz@nrubsig.org> | 2009-10-28 10:36:39 -0700 |
---|---|---|
committer | Roland Mainz <roland.mainz@nrubsig.org> | 2009-10-28 10:36:39 -0700 |
commit | 34f9b3eef6fdadbda0a846aa4d68691ac40eace5 (patch) | |
tree | 0b0fdfb35f8eb9324728de5a99e50e939aca650f /usr/src/lib/libcmd/common/pathchk.c | |
parent | 14969419acb89bb74e6c95fa472119b710224440 (diff) | |
download | illumos-joyent-34f9b3eef6fdadbda0a846aa4d68691ac40eace5.tar.gz |
Portions contributed by Olga Kryzhanovska <olga.kryzhanovska@gmail.com>
PSARC/2009/063 ksh93 update 2
PSARC/2009/248 ksh93 update to 2009-03-10
PSARC/2009/249 more ksh93 command conversions
6888396 libast sources should not include localedef.h
6605478 ksh93 profile shell option does not work
6631006 ksh93 hangs in situations that ksh handles okay
6661487 logname reports nothing after running the script command
6705126 first call to read doesn't honor new setting of HISTFILE
6764665 *libpp* Array overrun in libpp
6765756 *libast* Array overruns in libast
6769332 Recursive function+command substitutions terminate shell after 257 iterations
6777491 *ksh93* lacks arithmetric function iszero()
6778077 *ksh93* does not understand "THAW" as a signal for use with trap
6789247 [ku1] libast/ksh93 1-digit hexfloat base conversion rounds incorrectly
6791838 *ksh93* unset of a variable which is not set should return 0
6793714 RFE: Update /usr/bin/comm to AT&T AST "comm"
6793719 RFE: Update /usr/bin/cut to AT&T AST "cut"
6793721 RFE: Update /usr/bin/paste to AT&T AST "paste"
6793722 RFE: Update /usr/bin/cmp to AT&T AST "cmp"
6793726 RFE: Update /usr/bin/uniq to AT&T AST "uniq"
6793735 RFE: Update /usr/bin/wc to AT&T AST "wc"
6793744 RFE: Add /usr/share/doc/ksh/ for ksh93 documentation
6793747 RFE: Provide "print" builtin as /usr/bin/print for external applications
6793763 RFE: Update /usr/bin/ksh93 to ast-ksh.2009-05-05
6794952 RFE: Enable "globstar" mode in /etc/ksh.kshrc (= interactive ksh93 shells)
6805792 [ku1] Moving local compound var into array does not work
6805794 [ku1] printf returns "invalid character constant" for $ printf "%d\n" "'<euro>"
6805795 [ku1] ksh93 does not differ between -0 and +0
6805797 [ku1]Can't append to nodes of an array of compound vars if addressing them via nameref
6805799 Indexed compound variable arrays do not work...
6805800 [ku1] Declaring associative compound array does not work
6805813 RFE: Update /usr/bin/join to AT&T AST "join".
6805819 RFE: Update /usr/bin/tee to AT&T AST "tee".
6809663 shlint missing ending newline on errors
6811916 ksh93 repeatedly segfaults when "tee" builtin is interrupted via <ctrl-c> in interactive mode
6821113 SUNWosdem package issues
6828644 RFE: Update /usr/bin/logname to AT&T AST "logname".
6828692 RFE: Update /usr/bin/cksum to AT&T AST "cksum".
6834184 ksh93 gets SIGSEGV if HISTFILE is changed in place.
6834207 ksh93 gets SIGSEGV on interactive function definition with HISTSIZE unset
6835835 ksh93 "cat" builtin does not handle "-n" correctly
6841442 Need exception list for OS/Net trees managed via Subversion
6848486 "echo ${test}" with test undefined crashes the shell
6850672 ksh93 (VISUAL=vi) crashes with memory fault while scrolling through history
6855875 typeset -X x ; print $x # does not print sufficient digits to restore value
6857344 /usr/bin/hash core dump with invalid arguments
6866676 Need test suite module to test the kernel support for compiled shell scripts
6881017 Subshell doesn't exit, holds pipe open preventing callers from exiting
6884409 fts functions in libast library can result in segv with deep dir trees (similar to CERT VU#590371)
Diffstat (limited to 'usr/src/lib/libcmd/common/pathchk.c')
-rw-r--r-- | usr/src/lib/libcmd/common/pathchk.c | 154 |
1 files changed, 87 insertions, 67 deletions
diff --git a/usr/src/lib/libcmd/common/pathchk.c b/usr/src/lib/libcmd/common/pathchk.c index 7b0151d69c..ef27bd2788 100644 --- a/usr/src/lib/libcmd/common/pathchk.c +++ b/usr/src/lib/libcmd/common/pathchk.c @@ -1,7 +1,7 @@ /*********************************************************************** * * * This software is part of the ast package * -* Copyright (c) 1992-2008 AT&T Intellectual Property * +* Copyright (c) 1992-2009 AT&T Intellectual Property * * and is licensed under the * * Common Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -26,44 +26,50 @@ */ static const char usage[] = -"[-?\n@(#)$Id: pathchk (AT&T Research) 2006-09-19 $\n]" +"[-?\n@(#)$Id: pathchk (AT&T Research) 2009-07-24 $\n]" USAGE_LICENSE "[+NAME?pathchk - check pathnames for portability]" -"[+DESCRIPTION?\bpathchk\b checks each \apathname\a to see if it " - "is valid and/or portable. A \apathname\a is valid if it " - "can be used to access or create a file without causing syntax " - "errors. A file is portable, if no truncation will result on " - "any conforming POSIX.1 implementation.]" +"[+DESCRIPTION?\bpathchk\b checks each \apathname\a to see if it is " + "valid and/or portable. A \apathname\a is valid if it can be used to " + "access or create a file without causing syntax errors. A file is " + "portable if no truncation will result on any conforming POSIX.1 " + "implementation.]" "[+?By default \bpathchk\b checks each component of each \apathname\a " - "based on the underlying file system. A diagnostic is written " - "to standard error for each pathname that:]{" - "[+-?Is longer than \b$(getconf PATH_MAX)\b bytes.]" - "[+-?Contains any component longer than \b$(getconf NAME_MAX)\b bytes.]" - "[+-?Contains any directory component in a directory that is " - "not searchable.]" - "[+-?Contains any character in any component that is not valid in " - "its containing directory.]" - "[+-?Is empty.]" - "}" -"[p:portability?Instead of performing length checks on the underlying " - "file system, write a diagnostic for each pathname operand that:]{" - "[+-?Is longer than \b$(getconf _POSIX_PATH_MAX)\b bytes.]" - "[+-?Contains any component longer than " - "\b$(getconf _POSIX_NAME_MAX)\b bytes.]" + "based on the underlying file system. A diagnostic is written to " + "standard error for each pathname that:]" + "{" + "[+-?Is longer than \b$(getconf PATH_MAX)\b bytes.]" + "[+-?Contains any component longer than \b$(getconf NAME_MAX)\b " + "bytes.]" + "[+-?Contains any directory component in a directory that is not " + "searchable.]" + "[+-?Contains any character in any component that is not valid " + "in its containing directory.]" + "[+-?Is empty.]" + "}" +"[p:components?Instead of performing length checks on the underlying " + "file system, write a diagnostic for each pathname operand that:]" + "{" + "[+-?Is longer than \b$(getconf _POSIX_PATH_MAX)\b bytes.]" + "[+-?Contains any component longer than \b$(getconf " + "_POSIX_NAME_MAX)\b bytes.]" "[+-?Contains any character in any component that is not in the " - "portable filename character set.]" -#if 0 - "[+-?Contains any component with \b-\b as the first character.]" -#endif - "[+-?Is empty.]" - "}" + "portable filename character set.]" + "}" +"[P:path?Write a diagnostic for each pathname operand that:]" + "{" + "[+-?Contains any component with \b-\b as the first character.]" + "[+-?Is empty.]" + "}" +"[a:all|portability?Equivalent to \b--components\b \b--path\b.]" "\n" "\npathname ...\n" "\n" -"[+EXIT STATUS?]{" +"[+EXIT STATUS?]" + "{" "[+0?All \apathname\a operands passed all of the checks.]" "[+>0?An error occurred.]" -"}" + "}" "[+SEE ALSO?\bgetconf\b(1), \bcreat\b(2), \bpathchk\b(2)]" ; @@ -71,6 +77,9 @@ USAGE_LICENSE #include <cmd.h> #include <ls.h> +#define COMPONENTS 0x1 +#define PATH 0x2 + #define isport(c) (((c)>='a' && (c)<='z') || ((c)>='A' && (c)<='Z') || ((c)>='0' && (c)<='9') || (strchr("._-",(c))!=0) ) /* @@ -82,10 +91,10 @@ static long mypathconf(const char *path, int op) static const char* const ops[] = { "NAME_MAX", "PATH_MAX" }; - errno=0; - if((r=strtol(astconf(ops[op], path, NiL), NiL, 0))<0 && errno==0) - return(LONG_MAX); - return(r); + errno = 0; + if ((r = strtol(astconf(ops[op], path, NiL), NiL, 0)) < 0 && !errno) + return LONG_MAX; + return r; } /* @@ -100,10 +109,11 @@ static int pathchk(char* path, int mode) if(!*path) { - error(2,"path is empty"); - return(0); + if (mode & PATH) + error(2,"path is empty"); + return -1; } - if(mode) + if(mode & COMPONENTS) { name_max = _POSIX_NAME_MAX; path_max = _POSIX_PATH_MAX; @@ -177,7 +187,7 @@ static int pathchk(char* path, int mode) else if(errno==ENAMETOOLONG) { error(2,"%s: pathname too long",path); - return(0); + return -1; } #endif /*ENAMETOOLONG*/ else @@ -186,18 +196,18 @@ static int pathchk(char* path, int mode) } while(*(cpold=cp)) { - if(mode && *cp == '-') + if((mode & PATH) && *cp == '-') { error(2,"%s: path component begins with '-'",path,fmtquote(buf, NiL, "'", 1, 0)); - return(0); + return -1; } while((c= *cp++) && c!='/') - if(mode && !isport(c)) + if((mode & COMPONENTS) && !isport(c)) { buf[0] = c; buf[1] = 0; error(2,"%s: '%s' not in portable character set",path,fmtquote(buf, NiL, "'", 1, 0)); - return(0); + return -1; } if((cp-cpold) > name_max) goto err; @@ -208,41 +218,51 @@ static int pathchk(char* path, int mode) } if((cp-path) >= path_max) { - error(2,"%s: pathname too long",path); - return(0); + error(2, "%s: pathname too long", path); + return -1; } - return(1); -err: - error(2,"%s: component name %.*s too long",path,cp-cpold-1,cpold); - return(0); + return 0; + err: + error(2, "%s: component name %.*s too long", path, cp-cpold-1, cpold); + return -1; } int b_pathchk(int argc, char** argv, void* context) { - register int n, mode=0; - register char *cp; + register int n; + register int mode = 0; + register char* s; cmdinit(argc, argv, context, ERROR_CATALOG, 0); - while (n = optget(argv, usage)) switch (n) + for (;;) { - case 'p': - mode = 1; - break; - case ':': - error(2, "%s", opt_info.arg); - break; - case '?': - error(ERROR_usage(2), "%s", opt_info.arg); + switch (optget(argv, usage)) + { + case 0: + break; + case 'a': + mode |= COMPONENTS|PATH; + continue; + case 'p': + mode |= COMPONENTS; + continue; + case 'P': + mode |= PATH; + continue; + case ':': + error(2, "%s", opt_info.arg); + continue; + case '?': + error(ERROR_usage(2), "%s", opt_info.arg); + continue; + } break; } argv += opt_info.index; - if(*argv==0 || error_info.errors) - error(ERROR_usage(2),"%s", optusage((char*)0)); - while(cp = *argv++) - { - if(!pathchk(cp,mode)) - error_info.errors=1; - } - return(error_info.errors); + if (!*argv || error_info.errors) + error(ERROR_usage(2),"%s", optusage(NiL)); + while (s = *argv++) + pathchk(s, mode); + return error_info.errors != 0; } |