From: deraadt Date: Tue, 18 Sep 2018 06:56:09 +0000 (+0000) Subject: backout last week of csh diffs. They are disasterously broken, on i386 X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5f8675253d5eb0781685fc178ab9314f7916203d;p=openbsd backout last week of csh diffs. They are disasterously broken, on i386 it becomes entirely unusable. --- diff --git a/bin/csh/alloc.c b/bin/csh/alloc.c index c5d33636223..49af41d9543 100644 --- a/bin/csh/alloc.c +++ b/bin/csh/alloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: alloc.c,v 1.18 2018/09/18 02:29:10 miko Exp $ */ +/* $OpenBSD: alloc.c,v 1.19 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: alloc.c,v 1.6 1995/03/21 09:02:23 cgd Exp $ */ /*- @@ -39,7 +39,7 @@ #include "extern.h" void * -xmalloc(size_t n) +Malloc(size_t n) { void *ptr; @@ -51,7 +51,7 @@ xmalloc(size_t n) } void * -xreallocarray(void * p, size_t c, size_t n) +Reallocarray(void * p, size_t c, size_t n) { void *ptr; @@ -63,7 +63,7 @@ xreallocarray(void * p, size_t c, size_t n) } void * -xcalloc(size_t s, size_t n) +Calloc(size_t s, size_t n) { void *ptr; diff --git a/bin/csh/csh.h b/bin/csh/csh.h index 974db3e267a..fe324b36807 100644 --- a/bin/csh/csh.h +++ b/bin/csh/csh.h @@ -1,4 +1,4 @@ -/* $OpenBSD: csh.h,v 1.31 2018/09/18 02:29:10 miko Exp $ */ +/* $OpenBSD: csh.h,v 1.32 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: csh.h,v 1.9 1995/03/21 09:02:40 cgd Exp $ */ /*- @@ -69,6 +69,10 @@ typedef void *ioctl_t; /* Third arg of ioctl */ #include "char.h" #include "error.h" +#define xmalloc(i) Malloc(i) +#define xreallocarray(p, i, j) Reallocarray(p, i, j) +#define xcalloc(n, s) Calloc(n, s) + #include FILE *cshin, *cshout, *csherr; diff --git a/bin/csh/dol.c b/bin/csh/dol.c index efe27bdc5e1..3f2d510bfa1 100644 --- a/bin/csh/dol.c +++ b/bin/csh/dol.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dol.c,v 1.23 2018/09/17 16:00:19 martijn Exp $ */ +/* $OpenBSD: dol.c,v 1.24 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: dol.c,v 1.8 1995/09/27 00:38:38 jtc Exp $ */ /*- @@ -541,7 +541,7 @@ Dgetdol(void) for (i = 0; Isdigit(*np); i = i * 10 + *np++ - '0') continue; - if ((i < 0 || i > upb) && !strchr("-*", *np)) { + if ((i < 0 || i > upb) && !any("-*", *np)) { dolerror(vp->v_name); return; } @@ -642,7 +642,7 @@ fixDolMod(void) dolmod[dolnmod++] = delim; if (!delim || letter(delim) - || Isdigit(delim) || strchr(" \t\n", delim)) { + || Isdigit(delim) || any(" \t\n", delim)) { seterror(ERR_BADSUBST); break; } @@ -657,7 +657,7 @@ fixDolMod(void) } continue; } - if (!strchr("htrqxes", c)) + if (!any("htrqxes", c)) stderror(ERR_BADMOD, c); dolmod[dolnmod++] = c; if (c == 'q') @@ -691,7 +691,7 @@ setDolp(Char *cp) delim = dolmod[++i]; if (!delim || letter(delim) - || Isdigit(delim) || strchr(" \t\n", delim)) { + || Isdigit(delim) || any(" \t\n", delim)) { seterror(ERR_BADSUBST); break; } @@ -901,7 +901,7 @@ heredoc(Char *term) /* \ quotes \ $ ` here */ if (c == '\\') { c = DgetC(0); - if (!strchr("$\\`", c)) + if (!any("$\\`", c)) unDgetC(c | QUOTE), c = '\\'; else c |= QUOTE; @@ -918,7 +918,7 @@ heredoc(Char *term) * If any ` in line do command substitution */ mbp = mbuf; - if (strchr(short2str(mbp), '`')) { + if (any(short2str(mbp), '`')) { /* * 1 arg to dobackp causes substitution to be literal. Words are * broken only at newlines so that all blanks and tabs are diff --git a/bin/csh/error.c b/bin/csh/error.c index 6d8aa8321b2..069d1b8a626 100644 --- a/bin/csh/error.c +++ b/bin/csh/error.c @@ -1,4 +1,4 @@ -/* $OpenBSD: error.c,v 1.15 2018/09/15 12:15:32 miko Exp $ */ +/* $OpenBSD: error.c,v 1.16 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: err.c,v 1.6 1995/03/21 09:02:47 cgd Exp $ */ /*- @@ -289,7 +289,7 @@ seterror(int id, ...) vsnprintf(berr, sizeof(berr), errorlist[id], va); va_end(va); - seterr = xstrdup(berr); + seterr = strsave(berr); } } diff --git a/bin/csh/exec.c b/bin/csh/exec.c index 774eaa314df..73530dfae3d 100644 --- a/bin/csh/exec.c +++ b/bin/csh/exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec.c,v 1.20 2018/09/17 16:00:19 martijn Exp $ */ +/* $OpenBSD: exec.c,v 1.21 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: exec.c,v 1.9 1996/09/30 20:03:54 christos Exp $ */ /*- @@ -137,7 +137,7 @@ doexec(Char **v, struct command *t) blkfree(pv); pexerr(); } - slash = (bool) strchr(short2str(expath), '/'); + slash = any(short2str(expath), '/'); /* * Glob the argument list, if necessary. Otherwise trim off the quote bits. @@ -492,7 +492,7 @@ iscommand(Char *name) Char **pv; Char *sav; struct varent *v; - bool slash = (bool) strchr(short2str(name), '/'); + bool slash = any(short2str(name), '/'); int hashval = 0, hashval1, i; v = adrof(STRpath); @@ -680,7 +680,7 @@ tellmewhat(struct wordent *lexp, Char *str, int len) if ((i = iscommand(sp->word)) != 0) { Char **pv; struct varent *v; - bool slash = (bool) strchr(short2str(sp->word), '/'); + bool slash = any(short2str(sp->word), '/'); v = adrof(STRpath); if (v == 0 || v->vec[0] == 0 || slash) diff --git a/bin/csh/exp.c b/bin/csh/exp.c index 9ed891047c6..a62753d68e4 100644 --- a/bin/csh/exp.c +++ b/bin/csh/exp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exp.c,v 1.17 2018/09/17 16:00:19 martijn Exp $ */ +/* $OpenBSD: exp.c,v 1.18 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: exp.c,v 1.6 1995/03/21 09:02:51 cgd Exp $ */ /*- @@ -36,7 +36,6 @@ #include #include #include -#include #include "csh.h" #include "extern.h" @@ -239,7 +238,7 @@ exp3a(Char ***vp, bool ignore) p1 = exp4(vp, ignore); op = **vp; - if (op && strchr("<>", op[0]) && op[0] == op[1]) { + if (op && any("<>", op[0]) && op[0] == op[1]) { (*vp)++; p2 = exp3a(vp, ignore); if (op[0] == '<') @@ -393,7 +392,7 @@ exp6(Char ***vp, bool ignore) if (isa(**vp, ANYOP)) return (Strsave(STRNULL)); cp = *(*vp)++; - if (*cp == '-' && strchr("erwxfdzopls", cp[1])) { + if (*cp == '-' && any("erwxfdzopls", cp[1])) { struct stat stb; if (cp[2] != '\0') diff --git a/bin/csh/extern.h b/bin/csh/extern.h index 0b2481ac06f..e8e4fe6fb28 100644 --- a/bin/csh/extern.h +++ b/bin/csh/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.29 2018/09/18 02:29:10 miko Exp $ */ +/* $OpenBSD: extern.h,v 1.30 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: extern.h,v 1.8 1996/10/31 23:50:54 christos Exp $ */ /*- @@ -181,6 +181,7 @@ void unreadc(int); /* * misc.c */ +int any(char *, int); Char **blkcat(Char **, Char **); Char **blkcpy(Char **, Char **); Char **blkend(Char **); @@ -200,7 +201,7 @@ int prefix(Char *, Char *); Char **saveblk(Char **); Char *strip(Char *); Char *quote(Char *); -char *xstrdup(const char *); +char *strsave(char *); char *strspl(char *, char *); void udvar(Char *); @@ -280,9 +281,9 @@ void psecs(long); /* * alloc.c */ -void * xmalloc(size_t); -void * xreallocarray(void *, size_t, size_t); -void * xcalloc(size_t, size_t); +void * Malloc(size_t); +void * Reallocarray(void *, size_t, size_t); +void * Calloc(size_t, size_t); /* * str.c: diff --git a/bin/csh/lex.c b/bin/csh/lex.c index a26d0a79448..bcad8d7bb32 100644 --- a/bin/csh/lex.c +++ b/bin/csh/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.26 2018/09/17 16:00:19 martijn Exp $ */ +/* $OpenBSD: lex.c,v 1.27 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: lex.c,v 1.9 1995/09/27 00:38:46 jtc Exp $ */ /*- @@ -406,7 +406,7 @@ getdol(void) np = name, *np++ = '$'; c = sc = getC(DOEXCL); - if (strchr("\t \n", c)) { + if (any("\t \n", c)) { ungetD(c); ungetC('$' | QUOTE); return; @@ -550,7 +550,7 @@ getdol(void) *np++ = delim; if (!delim || letter(delim) - || Isdigit(delim) || strchr(" \t\n", delim)) { + || Isdigit(delim) || any(" \t\n", delim)) { seterror(ERR_BADSUBST); break; } @@ -565,7 +565,7 @@ getdol(void) } c = 's'; } - if (!strchr("htrqxes", c)) { + if (!any("htrqxes", c)) { if ((amodflag || gmodflag) && c == '\n') stderror(ERR_VARSYN); /* strike */ seterror(ERR_VARMOD, c); @@ -651,7 +651,7 @@ getexcl(int sc) goto subst; } c = getC(0); - if (!strchr(":^$*-%", c)) + if (!any(":^$*-%", c)) goto subst; left = right = -1; if (c == ':') { @@ -744,7 +744,7 @@ getsub(struct wordent *en) case 's': delim = getC(0); - if (letter(delim) || Isdigit(delim) || strchr(" \t\n", delim)) { + if (letter(delim) || Isdigit(delim) || any(" \t\n", delim)) { unreadc(delim); lhsb[0] = 0; seterror(ERR_BADSUBST); @@ -957,7 +957,7 @@ domod(Char *cp, int type) case 'h': case 't': - if (!strchr(short2str(cp), '/')) + if (!any(short2str(cp), '/')) return (type == 't' ? Strsave(cp) : 0); wp = Strend(cp); while (*--wp != '/') @@ -1067,7 +1067,7 @@ getsel(int *al, int *ar, int dol) if (first) { c = getC(0); unreadc(c); - if (strchr("-$*", c)) + if (any("-$*", c)) return (1); } if (*al > *ar || *ar > dol) { @@ -1122,14 +1122,14 @@ gethent(int sc) /* FALLSTHROUGH */ default: - if (strchr("(=~", c)) { + if (any("(=~", c)) { unreadc(c); ungetC(HIST); return (0); } np = lhsb; event = 0; - while (!cmap(c, _ESC | _META | _QF | _QB) && !strchr("${}:", c)) { + while (!cmap(c, _ESC | _META | _QF | _QB) && !any("${}:", c)) { if (event != -1 && Isdigit(c)) event = event * 10 + c - '0'; else diff --git a/bin/csh/misc.c b/bin/csh/misc.c index 0c508c442e1..08f456de03d 100644 --- a/bin/csh/misc.c +++ b/bin/csh/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.22 2018/09/17 16:00:19 martijn Exp $ */ +/* $OpenBSD: misc.c,v 1.23 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: misc.c,v 1.6 1995/03/21 09:03:09 cgd Exp $ */ /*- @@ -34,7 +34,6 @@ #include #include #include -#include #include "csh.h" #include "extern.h" @@ -42,17 +41,30 @@ static int fdcmp(int); static int renum(int, int); +int +any(char *s, int c) +{ + if (!s) + return (0); /* Check for nil pointer */ + while (*s) + if (*s++ == c) + return (1); + return (0); +} + char * -xstrdup(const char *s) +strsave(char *s) { - char *n; + char *n; + char *p; if (s == NULL) s = ""; - if ((n = strdup(s)) == NULL) { - child++; - stderror(ERR_NOMEM); - } + for (p = s; *p++;) + continue; + n = p = xreallocarray(NULL, (p - s), sizeof(char)); + while ((*p++ = *s++) != '\0') + continue; return (n); } diff --git a/bin/csh/parse.c b/bin/csh/parse.c index d8cd4098ec0..9b93e26569a 100644 --- a/bin/csh/parse.c +++ b/bin/csh/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.13 2018/09/17 16:00:19 martijn Exp $ */ +/* $OpenBSD: parse.c,v 1.14 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: parse.c,v 1.6 1995/03/21 09:03:10 cgd Exp $ */ /*- @@ -89,7 +89,7 @@ static void asyntax(struct wordent *p1, struct wordent *p2) { while (p1 != p2) - if (strchr(";&\n", p1->word[0])) + if (any(";&\n", p1->word[0])) p1 = p1->next; else { asyn0(p1, p2); @@ -214,7 +214,7 @@ syntax(struct wordent *p1, struct wordent *p2, int flags) { while (p1 != p2) - if (strchr(";&\n", p1->word[0])) + if (any(";&\n", p1->word[0])) p1 = p1->next; else return (syn0(p1, p2, flags)); @@ -516,7 +516,7 @@ again: } if (p->next == p2) continue; - if (strchr(RELPAR, p->next->word[0])) + if (any(RELPAR, p->next->word[0])) continue; n--; continue; @@ -576,7 +576,7 @@ again: continue; } p = p->next; - if (strchr(RELPAR, p->word[0])) { + if (any(RELPAR, p->word[0])) { seterror(ERR_MISRED); continue; } @@ -596,7 +596,7 @@ again: continue; } p = p->next; - if (strchr(RELPAR, p->word[0])) { + if (any(RELPAR, p->word[0])) { seterror(ERR_MISRED); continue; } diff --git a/bin/csh/set.c b/bin/csh/set.c index 0cece4f03ca..1298121337c 100644 --- a/bin/csh/set.c +++ b/bin/csh/set.c @@ -1,4 +1,4 @@ -/* $OpenBSD: set.c,v 1.20 2018/09/17 16:00:19 martijn Exp $ */ +/* $OpenBSD: set.c,v 1.21 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: set.c,v 1.8 1995/03/21 18:35:52 mycroft Exp $ */ /*- @@ -33,7 +33,6 @@ #include #include #include -#include #include "csh.h" #include "extern.h" @@ -244,13 +243,13 @@ dolet(Char **v, struct command *t) } else { c = *p++; - if (strchr("+-", c)) { + if (any("+-", c)) { if (c != op || *p) stderror(ERR_NAME | ERR_UNKNOWNOP); p = Strsave(STR1); } else { - if (strchr("<>", op)) { + if (any("<>", op)) { if (c != op) stderror(ERR_NAME | ERR_UNKNOWNOP); c = *p++; diff --git a/bin/csh/str.c b/bin/csh/str.c index 2355bab92bb..6efbfe29d7f 100644 --- a/bin/csh/str.c +++ b/bin/csh/str.c @@ -1,4 +1,4 @@ -/* $OpenBSD: str.c,v 1.20 2018/09/15 12:15:32 miko Exp $ */ +/* $OpenBSD: str.c,v 1.21 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: str.c,v 1.6 1995/03/21 09:03:24 cgd Exp $ */ /*- @@ -77,7 +77,7 @@ short2blk(Char **src) sdst = dst = xreallocarray(NULL, n + 1, sizeof(char *)); for (; *src != NULL; src++) - *dst++ = xstrdup(short2str(*src)); + *dst++ = strsave(short2str(*src)); *dst = NULL; return (sdst); } diff --git a/bin/csh/time.c b/bin/csh/time.c index b94ff2cb360..7483a898859 100644 --- a/bin/csh/time.c +++ b/bin/csh/time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: time.c,v 1.16 2018/09/17 16:00:19 martijn Exp $ */ +/* $OpenBSD: time.c,v 1.17 2018/09/18 06:56:09 deraadt Exp $ */ /* $NetBSD: time.c,v 1.7 1995/03/21 13:55:25 mycroft Exp $ */ /*- @@ -32,7 +32,6 @@ #include #include -#include #include "csh.h" #include "extern.h" @@ -84,7 +83,7 @@ donice(Char **v, struct command *t) v++, cp = *v++; if (cp == 0) nval = 4; - else if (*v == 0 && strchr("+-", cp[0])) + else if (*v == 0 && any("+-", cp[0])) nval = getn(cp); (void) setpriority(PRIO_PROCESS, 0, nval); }