diff options
author | dchagin <dchagin@FreeBSD.org> | 2017-04-15 11:13:11 +0000 |
---|---|---|
committer | dchagin <dchagin@FreeBSD.org> | 2017-04-15 11:13:11 +0000 |
commit | 9878fb1e0f314058f4c30cc4c77722f00e17188a (patch) | |
tree | 2f0dd759511c9fea5ee93d228684a99622ed5e8e /contrib/tcsh/sh.glob.c | |
parent | 21382a2b98c257da842adc1f651f3e207dd235af (diff) | |
download | FreeBSD-src-9878fb1e0f314058f4c30cc4c77722f00e17188a.zip FreeBSD-src-9878fb1e0f314058f4c30cc4c77722f00e17188a.tar.gz |
MFC r315948:
Update tcsh to 6.20.00
MFC r315952:
Update tcsh to vendor git b605cb561d
Vendor changes:
1. PR/471: Daiki Ueno: Delay interpreting arginp until we've processed
our startup files (which can change the NLS environment).
2. Fix type of read in prompt confirmation (eg. rmstar) (David Kaspar).
3. Fix out of bounds read (Brooks Davis)
(reproduce by starting tcsh and hitting tab at the prompt).
4. Don't play pointer tricks that are undefined in modern c
(Brooks Davis).
Diffstat (limited to 'contrib/tcsh/sh.glob.c')
-rw-r--r-- | contrib/tcsh/sh.glob.c | 84 |
1 files changed, 33 insertions, 51 deletions
diff --git a/contrib/tcsh/sh.glob.c b/contrib/tcsh/sh.glob.c index 16be77e..f6e32f1 100644 --- a/contrib/tcsh/sh.glob.c +++ b/contrib/tcsh/sh.glob.c @@ -1,4 +1,4 @@ -/* $Header: /p/tcsh/cvsroot/tcsh/sh.glob.c,v 3.82 2011/02/27 00:15:17 christos Exp $ */ +/* $Header: /p/tcsh/cvsroot/tcsh/sh.glob.c,v 3.95 2016/08/01 16:21:09 christos Exp $ */ /* * sh.glob.c: Regular expression expansion */ @@ -32,7 +32,7 @@ */ #include "sh.h" -RCSID("$tcsh: sh.glob.c,v 3.82 2011/02/27 00:15:17 christos Exp $") +RCSID("$tcsh: sh.glob.c,v 3.95 2016/08/01 16:21:09 christos Exp $") #include "tc.h" #include "tw.h" @@ -594,8 +594,13 @@ trim(Char **t) Char *p; while ((p = *t++) != '\0') - while (*p) - *p++ &= TRIM; + while (*p) { +#if INVALID_BYTE != 0 + if ((*p & INVALID_BYTE) != INVALID_BYTE) /* *p < INVALID_BYTE */ +#endif + *p &= TRIM; + p++; + } } int @@ -699,11 +704,15 @@ backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal) int hadnl; int pvec[2], quoted; Char *fakecom[2], ibuf[BUFSIZE]; - char tibuf[BUFSIZE]; hadnl = 0; icnt = 0; - quoted = (literal || (cp[0] & QUOTE)) ? QUOTE : 0; + if (!literal) { + for (ip = cp; (*ip & QUOTE) != 0; ip++) + continue; + quoted = *ip == '\0'; + } else + quoted = literal; faket.t_dtyp = NODE_COMMAND; faket.t_dflg = F_BACKQ; faket.t_dlef = 0; @@ -760,6 +769,9 @@ backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal) omark = cleanup_push_mark(); getexit(osetexit); for (;;) { + struct wordent paraml1; + initlex(¶ml1); + (void) setexit(); justpr = 0; @@ -775,19 +787,19 @@ backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal) seterr = NULL; } - (void) lex(¶ml); - cleanup_push(¶ml, lex_cleanup); + freelex(¶ml1); + (void) lex(¶ml1); + cleanup_push(¶ml1, lex_cleanup); if (seterr) stderror(ERR_OLD); - alias(¶ml); - t = syntax(paraml.next, ¶ml, 0); - if (t == NULL) - return; + alias(¶ml1); + t = syntax(paraml1.next, ¶ml1, 0); cleanup_push(t, syntax_cleanup); /* The F_BACKQ flag must set so the job output is correct if * printexitvalue is set. If it's not set, the job output * will have "Exit N" appended where N is the exit status. */ - t->t_dflg = F_BACKQ|F_NOFORK; + if (t) + t->t_dflg = F_BACKQ|F_NOFORK; if (seterr) stderror(ERR_OLD); #ifdef SIGTSTP @@ -801,7 +813,7 @@ backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal) #endif execute(t, -1, NULL, NULL, TRUE); - cleanup_until(¶ml); + cleanup_until(¶ml1); } } cleanup_until(&pvec[1]); @@ -809,45 +821,13 @@ backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal) ip = NULL; do { ssize_t cnt = 0; - char *tmp; - tmp = tibuf; for (;;) { - while (icnt == 0) { - int i, eof; - + if (icnt == 0) { ip = ibuf; - icnt = xread(pvec[0], tmp, tibuf + BUFSIZE - tmp); - eof = 0; - if (icnt <= 0) { - if (tmp == tibuf) - goto eof; - icnt = 0; - eof = 1; - } - icnt += tmp - tibuf; - i = 0; - tmp = tibuf; - while (tmp < tibuf + icnt) { - int len; - - len = normal_mbtowc(&ip[i], tmp, tibuf + icnt - tmp); - if (len == -1) { - reset_mbtowc(); - if (!eof && (size_t)(tibuf + icnt - tmp) < MB_CUR_MAX) { - break; /* Maybe a partial character */ - } - ip[i] = (unsigned char) *tmp | INVALID_BYTE; /* Error */ - } - if (len <= 0) - len = 1; - i++; - tmp += len; - } - if (tmp != tibuf) - memmove (tibuf, tmp, tibuf + icnt - tmp); - tmp = tibuf + (tibuf + icnt - tmp); - icnt = i; + icnt = wide_read(pvec[0], ibuf, BUFSIZE, 0); + if (icnt <= 0) + goto eof; } if (hadnl) break; @@ -870,7 +850,9 @@ backeval(struct blk_buf *bb, struct Strbuf *word, Char *cp, int literal) if (!quoted && (c == ' ' || c == '\t')) break; cnt++; - Strbuf_append1(word, c | quoted); + if (c == '\\' || quoted) + c |= QUOTE; + Strbuf_append1(word, c); } /* * Unless at end-of-file, we will form a new word here if there were |