From d2867740a30eb85dc7d56c52bb5dddfca3ff3b24 Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Tue, 23 Oct 2018 12:40:20 -0700 Subject: Update sh to r338473 --- external/sh/cd.c | 4 ++-- external/sh/exec.c | 54 +++++++++++++++++++++++++++++--------------------- external/sh/exec.h | 5 ++--- external/sh/expand.c | 10 ++++++---- external/sh/jobs.c | 17 ++++++++-------- external/sh/mail.c | 32 ++++++++++++++++-------------- external/sh/main.c | 5 +++-- external/sh/mkbuiltins | 4 ++-- external/sh/parser.c | 6 ++++-- external/sh/printf.c | 12 +++++++---- external/sh/syntax.c | 6 +++--- external/sh/syntax.h | 29 ++++++++++++++------------- external/sh/var.c | 2 +- 13 files changed, 103 insertions(+), 83 deletions(-) (limited to 'external') diff --git a/external/sh/cd.c b/external/sh/cd.c index cf63681f..e22669fd 100644 --- a/external/sh/cd.c +++ b/external/sh/cd.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)cd.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/cd.c 320340 2017-06-25 21:53:08Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/cd.c 336320 2018-07-15 21:55:17Z jilles $"); #include #include @@ -120,7 +120,7 @@ cdcmd(int argc __unused, char **argv __unused) (dest[0] == '.' && dest[1] == '.' && (dest[2] == '/' || dest[2] == '\0')) || (path = bltinlookup("CDPATH", 1)) == NULL) path = ""; - while ((p = padvance(&path, dest)) != NULL) { + while ((p = padvance(&path, NULL, dest)) != NULL) { if (stat(p, &statb) < 0) { if (errno != ENOENT) errno1 = errno; diff --git a/external/sh/exec.c b/external/sh/exec.c index 4b18c57f..067455bf 100644 --- a/external/sh/exec.c +++ b/external/sh/exec.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/exec.c 317882 2017-05-06 13:28:42Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/exec.c 336320 2018-07-15 21:55:17Z jilles $"); #include #include @@ -113,6 +113,7 @@ void shellexec(char **argv, char **envp, const char *path, int idx) { char *cmdname; + const char *opt; int e; if (strchr(argv[0], '/') != NULL) { @@ -120,8 +121,8 @@ shellexec(char **argv, char **envp, const char *path, int idx) e = errno; } else { e = ENOENT; - while ((cmdname = padvance(&path, argv[0])) != NULL) { - if (--idx < 0 && pathopt == NULL) { + while ((cmdname = padvance(&path, &opt, argv[0])) != NULL) { + if (--idx < 0 && opt == NULL) { tryexec(cmdname, argv, envp); if (errno != ENOENT && errno != ENOTDIR) e = errno; @@ -174,16 +175,14 @@ tryexec(char *cmd, char **argv, char **envp) * Do a path search. The variable path (passed by reference) should be * set to the start of the path before the first call; padvance will update * this value as it proceeds. Successive calls to padvance will return - * the possible path expansions in sequence. If an option (indicated by - * a percent sign) appears in the path entry then the global variable - * pathopt will be set to point to it; otherwise pathopt will be set to - * NULL. + * the possible path expansions in sequence. If popt is not NULL, options + * are processed: if an option (indicated by a percent sign) appears in + * the path entry then *popt will be set to point to it; else *popt will be + * set to NULL. If popt is NULL, percent signs are not special. */ -const char *pathopt; - char * -padvance(const char **path, const char *name) +padvance(const char **path, const char **popt, const char *name) { const char *p, *start; char *q; @@ -192,8 +191,12 @@ padvance(const char **path, const char *name) if (*path == NULL) return NULL; start = *path; - for (p = start; *p && *p != ':' && *p != '%'; p++) - ; /* nothing */ + if (popt != NULL) + for (p = start; *p && *p != ':' && *p != '%'; p++) + ; /* nothing */ + else + for (p = start; *p && *p != ':'; p++) + ; /* nothing */ namelen = strlen(name); len = p - start + namelen + 2; /* "2" is for '/' and '\0' */ STARTSTACKSTR(q); @@ -204,10 +207,12 @@ padvance(const char **path, const char *name) *q++ = '/'; } memcpy(q, name, namelen + 1); - pathopt = NULL; - if (*p == '%') { - pathopt = ++p; - while (*p && *p != ':') p++; + if (popt != NULL) { + if (*p == '%') { + *popt = ++p; + while (*p && *p != ':') p++; + } else + *popt = NULL; } if (*p == ':') *path = p + 1; @@ -277,14 +282,14 @@ static void printentry(struct tblentry *cmdp, int verbose) { int idx; - const char *path; + const char *path, *opt; char *name; if (cmdp->cmdtype == CMDNORMAL) { idx = cmdp->param.index; path = pathval(); do { - name = padvance(&path, cmdp->cmdname); + name = padvance(&path, &opt, cmdp->cmdname); stunalloc(name); } while (--idx >= 0); out1str(name); @@ -321,6 +326,7 @@ find_command(const char *name, struct cmdentry *entry, int act, { struct tblentry *cmdp, loc_cmd; int idx; + const char *opt; char *fullname; struct stat statb; int e; @@ -363,10 +369,11 @@ find_command(const char *name, struct cmdentry *entry, int act, e = ENOENT; idx = -1; - for (;(fullname = padvance(&path, name)) != NULL; stunalloc(fullname)) { + for (;(fullname = padvance(&path, &opt, name)) != NULL; + stunalloc(fullname)) { idx++; - if (pathopt) { - if (strncmp(pathopt, "func", 4) == 0) { + if (opt) { + if (strncmp(opt, "func", 4) == 0) { /* handled below */ } else { continue; /* ignore unimplemented options */ @@ -382,7 +389,7 @@ find_command(const char *name, struct cmdentry *entry, int act, e = EACCES; /* if we fail, this will be the error */ if (!S_ISREG(statb.st_mode)) continue; - if (pathopt) { /* this is a %func directory */ + if (opt) { /* this is a %func directory */ readcmdfile(fullname); if ((cmdp = cmdlookup(name, 0)) == NULL || cmdp->cmdtype != CMDFUNCTION) error("%s not defined in %s", name, fullname); @@ -703,10 +710,11 @@ typecmd_impl(int argc, char **argv, int cmd, const char *path) case CMDNORMAL: { if (strchr(argv[i], '/') == NULL) { const char *path2 = path; + const char *opt2; char *name; int j = entry.u.index; do { - name = padvance(&path2, argv[i]); + name = padvance(&path2, &opt2, argv[i]); stunalloc(name); } while (--j >= 0); if (cmd == TYPECMD_SMALLV) diff --git a/external/sh/exec.h b/external/sh/exec.h index 352077fe..d13907bd 100644 --- a/external/sh/exec.h +++ b/external/sh/exec.h @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * @(#)exec.h 8.3 (Berkeley) 6/8/95 - * $FreeBSD: head/bin/sh/exec.h 314436 2017-02-28 23:42:47Z imp $ + * $FreeBSD: head/bin/sh/exec.h 336320 2018-07-15 21:55:17Z jilles $ */ /* values of cmdtype */ @@ -61,11 +61,10 @@ struct cmdentry { #define DO_ERR 0x01 /* prints errors */ #define DO_NOFUNC 0x02 /* don't return shell functions, for command */ -extern const char *pathopt; /* set by padvance */ extern int exerrno; /* last exec error */ void shellexec(char **, char **, const char *, int) __dead2; -char *padvance(const char **, const char *); +char *padvance(const char **, const char **, const char *); void find_command(const char *, struct cmdentry *, int, const char *); int find_builtin(const char *, int *); void hashcd(void); diff --git a/external/sh/expand.c b/external/sh/expand.c index 7a31c959..117fd2ff 100644 --- a/external/sh/expand.c +++ b/external/sh/expand.c @@ -40,7 +40,7 @@ static char sccsid[] = "@(#)expand.c 8.5 (Berkeley) 5/15/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/expand.c 318269 2017-05-14 13:14:19Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/expand.c 338473 2018-09-05 19:16:09Z jilles $"); #include #include @@ -896,7 +896,7 @@ reprocess(int startloc, int flag, int subtype, int quoted, startp = stackblock() + startloc; len = expdest - startp; - if (len >= SIZE_MAX / 2) + if (len >= SIZE_MAX / 2 || len > PTRDIFF_MAX) abort(); INTOFF; if (len >= buflen) { @@ -912,7 +912,7 @@ reprocess(int startloc, int flag, int subtype, int quoted, INTON; memcpy(buf, startp, len); buf[len] = '\0'; - STADJUST(-len, expdest); + STADJUST(-(ptrdiff_t)len, expdest); for (zpos = 0;;) { zlen = strlen(buf + zpos); strtodest(buf + zpos, flag, subtype, quoted, dst); @@ -1342,8 +1342,10 @@ patmatch(const char *pattern, const char *string) } if (c == '[' && *p == ':') { found |= match_charclass(p, chr, &end); - if (end != NULL) + if (end != NULL) { p = end; + continue; + } } if (c == CTLESC) c = *p++; diff --git a/external/sh/jobs.c b/external/sh/jobs.c index 999c2519..358153bd 100644 --- a/external/sh/jobs.c +++ b/external/sh/jobs.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)jobs.c 8.5 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/jobs.c 327475 2018-01-01 22:31:52Z jilles $"); +__FBSDID("$FreeBSD: head/bin/sh/jobs.c 328818 2018-02-02 22:53:58Z jilles $"); #include #include @@ -362,7 +362,7 @@ showjob(struct job *jp, int mode) const char *statestr, *coredump; struct procstat *ps; struct job *j; - int col, curr, i, jobno, prev, procno; + int col, curr, i, jobno, prev, procno, status; char c; procno = (mode == SHOWJOBS_PGIDS) ? 1 : jp->nprocs; @@ -376,11 +376,12 @@ showjob(struct job *jp, int mode) } #endif coredump = ""; - ps = jp->ps + jp->nprocs - 1; + status = jp->ps[jp->nprocs - 1].status; if (jp->state == 0) { statestr = "Running"; #if JOBS } else if (jp->state == JOBSTOPPED) { + ps = jp->ps + jp->nprocs - 1; while (!WIFSTOPPED(ps->status) && ps > jp->ps) ps--; if (WIFSTOPPED(ps->status)) @@ -391,20 +392,20 @@ showjob(struct job *jp, int mode) if (statestr == NULL) statestr = "Suspended"; #endif - } else if (WIFEXITED(ps->status)) { - if (WEXITSTATUS(ps->status) == 0) + } else if (WIFEXITED(status)) { + if (WEXITSTATUS(status) == 0) statestr = "Done"; else { fmtstr(statebuf, sizeof(statebuf), "Done(%d)", - WEXITSTATUS(ps->status)); + WEXITSTATUS(status)); statestr = statebuf; } } else { - i = WTERMSIG(ps->status); + i = WTERMSIG(status); statestr = strsignal(i); if (statestr == NULL) statestr = "Unknown signal"; - if (WCOREDUMP(ps->status)) + if (WCOREDUMP(status)) coredump = " (core dumped)"; } diff --git a/external/sh/mail.c b/external/sh/mail.c index 607b4074..bbf5e404 100644 --- a/external/sh/mail.c +++ b/external/sh/mail.c @@ -36,14 +36,13 @@ static char sccsid[] = "@(#)mail.c 8.2 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/mail.c 314436 2017-02-28 23:42:47Z imp $"); +__FBSDID("$FreeBSD: head/bin/sh/mail.c 336303 2018-07-15 09:14:30Z jilles $"); /* * Routines to check for mail. (Perhaps make part of main.c?) */ #include "shell.h" -#include "exec.h" /* defines padvance() */ #include "mail.h" #include "var.h" #include "output.h" @@ -72,9 +71,9 @@ void chkmail(int silent) { int i; - const char *mpath; + char *mpath; char *p; - char *q; + char *msg; struct stackmark smark; struct stat statb; @@ -83,22 +82,25 @@ chkmail(int silent) if (nmboxes == 0) return; setstackmark(&smark); - mpath = mpathset()? mpathval() : mailval(); + mpath = stsavestr(mpathset()? mpathval() : mailval()); for (i = 0 ; i < nmboxes ; i++) { - p = padvance(&mpath, ""); - if (p == NULL) - break; + p = mpath; if (*p == '\0') - continue; - for (q = p ; *q ; q++); - if (q[-1] != '/') - abort(); - q[-1] = '\0'; /* delete trailing '/' */ + break; + mpath = strchrnul(mpath, ':'); + if (*mpath != '\0') { + *mpath++ = '\0'; + if (p == mpath - 1) + continue; + } + msg = strchr(p, '%'); + if (msg != NULL) + *msg++ = '\0'; #ifdef notdef /* this is what the System V shell claims to do (it lies) */ if (stat(p, &statb) < 0) statb.st_mtime = 0; if (statb.st_mtime > mailtime[i] && ! silent) { - out2str(pathopt? pathopt : "you have mail"); + out2str(msg? msg : "you have mail"); out2c('\n'); } mailtime[i] = statb.st_mtime; @@ -106,7 +108,7 @@ chkmail(int silent) if (stat(p, &statb) < 0) statb.st_size = 0; if (statb.st_size > mailtime[i] && ! silent) { - out2str(pathopt? pathopt : "you have mail"); + out2str(msg? msg : "you have mail"); out2c('\n'); } mailtime[i] = statb.st_size; diff --git a/external/sh/main.c b/external/sh/main.c index 338f97cf..064662fa 100644 --- a/external/sh/main.c +++ b/external/sh/main.c @@ -44,7 +44,7 @@ static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/28/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/main.c 326025 2017-11-20 19:49:47Z pfg $"); +__FBSDID("$FreeBSD: head/bin/sh/main.c 336320 2018-07-15 21:55:17Z jilles $"); #include #include @@ -294,6 +294,7 @@ static char * find_dot_file(char *basename) { char *fullname; + const char *opt; const char *path = pathval(); struct stat statb; @@ -301,7 +302,7 @@ find_dot_file(char *basename) if( strchr(basename, '/')) return basename; - while ((fullname = padvance(&path, basename)) != NULL) { + while ((fullname = padvance(&path, &opt, basename)) != NULL) { if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) { /* * Don't bother freeing here, since it will diff --git a/external/sh/mkbuiltins b/external/sh/mkbuiltins index 799be589..7c2cef1d 100755 --- a/external/sh/mkbuiltins +++ b/external/sh/mkbuiltins @@ -32,9 +32,9 @@ # SUCH DAMAGE. # # @(#)mkbuiltins 8.2 (Berkeley) 5/4/95 -# $FreeBSD: head/bin/sh/mkbuiltins 319576 2017-06-04 21:02:48Z bdrewery $ +# $FreeBSD: head/bin/sh/mkbuiltins 328934 2018-02-06 15:41:35Z arichardson $ -temp=`/usr/bin/mktemp -t ka` +temp=`mktemp -t ka` havehist=1 if [ "X$1" = "X-h" ]; then havehist=0 diff --git a/external/sh/parser.c b/external/sh/parser.c index 799e3b53..9da2ea6d 100644 --- a/external/sh/parser.c +++ b/external/sh/parser.c @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)parser.c 8.7 (Berkeley) 5/16/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/parser.c 326025 2017-11-20 19:49:47Z pfg $"); +__FBSDID("$FreeBSD: head/bin/sh/parser.c 334008 2018-05-21 21:52:48Z jilles $"); #include #include @@ -1434,8 +1434,10 @@ readtoken1(int firstc, char const *initialsyntax, const char *eofmark, switch(synentry) { case CNL: /* '\n' */ - if (state[level].syntax == BASESYNTAX) + if (level == 0) goto endword; /* exit outer loop */ + /* FALLTHROUGH */ + case CQNL: USTPUTC(c, out); plinno++; if (doprompt) diff --git a/external/sh/printf.c b/external/sh/printf.c index c391d039..266668ec 100644 --- a/external/sh/printf.c +++ b/external/sh/printf.c @@ -1,6 +1,7 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * + * Copyright 2018 Staysail Systems, Inc. * Copyright 2014 Garrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 1989, 1993 @@ -48,7 +49,7 @@ static char const copyright[] = static char const sccsid[] = "@(#)printf.c 8.1 (Berkeley) 7/20/93"; #endif static const char rcsid[] = - "$FreeBSD: head/usr.bin/printf/printf.c 326025 2017-11-20 19:49:47Z pfg $"; + "$FreeBSD: head/usr.bin/printf/printf.c 337618 2018-08-11 11:13:34Z jilles $"; #endif /* not lint */ #include @@ -375,13 +376,16 @@ printf_doformat(char *fmt, int *rval) char *p; int getout; - p = strdup(getstr()); - if (p == NULL) { + /* Convert "b" to "s" for output. */ + start[strlen(start) - 1] = 's'; + if ((p = strdup(getstr())) == NULL) { warnx("%s", strerror(ENOMEM)); return (NULL); } getout = escape(p, 0, &len); - fputs(p, stdout); + PF(start, p); + /* Restore format for next loop. */ + free(p); if (getout) return (end_fmt); diff --git a/external/sh/syntax.c b/external/sh/syntax.c index 28f9b62d..bd5c76ea 100644 --- a/external/sh/syntax.c +++ b/external/sh/syntax.c @@ -48,7 +48,7 @@ const char dqsyntax[SYNBASE + CHAR_MAX + 1] = { [SYNBASE + CTLENDARI] = CCTL, [SYNBASE + CTLQUOTEMARK] = CCTL, [SYNBASE + CTLQUOTEEND] = CCTL, - [SYNBASE + '\n'] = CNL, + [SYNBASE + '\n'] = CQNL, [SYNBASE + '\\'] = CBACK, [SYNBASE + '"'] = CENDQUOTE, [SYNBASE + '`'] = CBQUOTE, @@ -79,7 +79,7 @@ const char sqsyntax[SYNBASE + CHAR_MAX + 1] = { [SYNBASE + CTLENDARI] = CCTL, [SYNBASE + CTLQUOTEMARK] = CCTL, [SYNBASE + CTLQUOTEEND] = CCTL, - [SYNBASE + '\n'] = CNL, + [SYNBASE + '\n'] = CQNL, [SYNBASE + '\\'] = CSBACK, [SYNBASE + '\''] = CENDQUOTE, [SYNBASE + '!'] = CCTL, @@ -107,7 +107,7 @@ const char arisyntax[SYNBASE + CHAR_MAX + 1] = { [SYNBASE + CTLENDARI] = CCTL, [SYNBASE + CTLQUOTEMARK] = CCTL, [SYNBASE + CTLQUOTEEND] = CCTL, - [SYNBASE + '\n'] = CNL, + [SYNBASE + '\n'] = CQNL, [SYNBASE + '\\'] = CBACK, [SYNBASE + '`'] = CBQUOTE, [SYNBASE + '"'] = CIGN, diff --git a/external/sh/syntax.h b/external/sh/syntax.h index e9cf2e90..6bf2fb80 100644 --- a/external/sh/syntax.h +++ b/external/sh/syntax.h @@ -8,20 +8,21 @@ /* Syntax classes */ #define CWORD 0 /* character is nothing special */ #define CNL 1 /* newline character */ -#define CBACK 2 /* a backslash character */ -#define CSBACK 3 /* a backslash character in single quotes */ -#define CSQUOTE 4 /* single quote */ -#define CDQUOTE 5 /* double quote */ -#define CENDQUOTE 6 /* a terminating quote */ -#define CBQUOTE 7 /* backwards single quote */ -#define CVAR 8 /* a dollar sign */ -#define CENDVAR 9 /* a '}' character */ -#define CLP 10 /* a left paren in arithmetic */ -#define CRP 11 /* a right paren in arithmetic */ -#define CEOF 12 /* end of file */ -#define CCTL 13 /* like CWORD, except it must be escaped */ -#define CSPCL 14 /* these terminate a word */ -#define CIGN 15 /* character should be ignored */ +#define CQNL 2 /* newline character in quotes */ +#define CBACK 3 /* a backslash character */ +#define CSBACK 4 /* a backslash character in single quotes */ +#define CSQUOTE 5 /* single quote */ +#define CDQUOTE 6 /* double quote */ +#define CENDQUOTE 7 /* a terminating quote */ +#define CBQUOTE 8 /* backwards single quote */ +#define CVAR 9 /* a dollar sign */ +#define CENDVAR 10 /* a '}' character */ +#define CLP 11 /* a left paren in arithmetic */ +#define CRP 12 /* a right paren in arithmetic */ +#define CEOF 13 /* end of file */ +#define CCTL 14 /* like CWORD, except it must be escaped */ +#define CSPCL 15 /* these terminate a word */ +#define CIGN 16 /* character should be ignored */ /* Syntax classes for is_ functions */ #define ISDIGIT 01 /* a digit */ diff --git a/external/sh/var.c b/external/sh/var.c index 5a412f88..feeea03c 100644 --- a/external/sh/var.c +++ b/external/sh/var.c @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 5/4/95"; #endif #endif /* not lint */ #include -__FBSDID("$FreeBSD: head/bin/sh/var.c 326025 2017-11-20 19:49:47Z pfg $"); +__FBSDID("$FreeBSD: head/bin/sh/var.c 329221 2018-02-13 16:48:57Z bdrewery $"); #include #include -- cgit v1.2.3