diff options
author | 2013-12-17 16:37:05 +0000 | |
---|---|---|
committer | 2013-12-17 16:37:05 +0000 | |
commit | e569fc7c5c44c314841185018cc86ae78a5d6372 (patch) | |
tree | 9bca923dba491cbb2dd81114d1c024c183374bab | |
parent | sync (diff) | |
download | wireguard-openbsd-e569fc7c5c44c314841185018cc86ae78a5d6372.tar.xz wireguard-openbsd-e569fc7c5c44c314841185018cc86ae78a5d6372.zip |
ctype cleanups. Repeated re-audits of this sensitive area by okan and
myself, with a variety of other people spending some time as well.
Thanks.
-rw-r--r-- | bin/ksh/c_ksh.c | 5 | ||||
-rw-r--r-- | bin/ksh/edit.c | 5 | ||||
-rw-r--r-- | bin/ksh/emacs.c | 30 | ||||
-rw-r--r-- | bin/ksh/expr.c | 4 | ||||
-rw-r--r-- | bin/ksh/io.c | 4 | ||||
-rw-r--r-- | bin/ksh/lex.c | 4 | ||||
-rw-r--r-- | bin/ksh/var.c | 18 | ||||
-rw-r--r-- | bin/ksh/vi.c | 49 |
8 files changed, 65 insertions, 54 deletions
diff --git a/bin/ksh/c_ksh.c b/bin/ksh/c_ksh.c index e653975aeb1..f89afef7ff7 100644 --- a/bin/ksh/c_ksh.c +++ b/bin/ksh/c_ksh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_ksh.c,v 1.33 2009/02/07 14:03:24 kili Exp $ */ +/* $OpenBSD: c_ksh.c,v 1.34 2013/12/17 16:37:05 deraadt Exp $ */ /* * built-in Korn commands: c_* @@ -1135,7 +1135,8 @@ c_kill(char **wp) int i, n, rv, sig; /* assume old style options if -digits or -UPPERCASE */ - if ((p = wp[1]) && *p == '-' && (digit(p[1]) || isupper(p[1]))) { + if ((p = wp[1]) && *p == '-' && + (digit(p[1]) || isupper((unsigned char)p[1]))) { if (!(t = gettrap(p + 1, true))) { bi_errorf("bad signal `%s'", p + 1); return 1; diff --git a/bin/ksh/edit.c b/bin/ksh/edit.c index 32d07147fda..4b3dd786c12 100644 --- a/bin/ksh/edit.c +++ b/bin/ksh/edit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: edit.c,v 1.38 2013/06/03 15:41:59 tedu Exp $ */ +/* $OpenBSD: edit.c,v 1.39 2013/12/17 16:37:05 deraadt Exp $ */ /* * Command line editing - common code @@ -549,7 +549,8 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp, int iscmd; /* Figure out if this is a command */ - for (p = start - 1; p >= 0 && isspace(buf[p]); p--) + for (p = start - 1; p >= 0 && isspace((unsigned char)buf[p]); + p--) ; iscmd = p < 0 || strchr(";|&()`", buf[p]); if (iscmd) { diff --git a/bin/ksh/emacs.c b/bin/ksh/emacs.c index 233ee9c4e41..31cbe85716d 100644 --- a/bin/ksh/emacs.c +++ b/bin/ksh/emacs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: emacs.c,v 1.47 2013/11/28 10:33:37 sobrado Exp $ */ +/* $OpenBSD: emacs.c,v 1.48 2013/12/17 16:37:05 deraadt Exp $ */ /* * Emacs-like command line editing and history @@ -47,7 +47,9 @@ struct x_ftab { /* Separator for completion */ #define is_cfs(c) (c == ' ' || c == '\t' || c == '"' || c == '\'') -#define is_mfs(c) (!(isalnum(c) || c == '_' || c == '$')) /* Separator for motion */ + +/* Separator for motion */ +#define is_mfs(c) (!(isalnum((unsigned char)c) || c == '_' || c == '$')) /* Arguments for do_complete() * 0 = enumerate M-= complete as much as possible and then list @@ -529,7 +531,7 @@ x_delete(int nc, int push) j = 0; i = nc; while (i--) { - j += x_size(*cp++); + j += x_size((unsigned char)*cp++); } memmove(xcp, xcp+nc, xep - xcp + 1); /* Copies the null */ x_adj_ok = 0; /* don't redraw */ @@ -641,10 +643,10 @@ x_goto(char *cp) x_adjust(); } else if (cp < xcp) { /* move back */ while (cp < xcp) - x_bs(*--xcp); + x_bs((unsigned char)*--xcp); } else if (cp > xcp) { /* move forward */ while (cp > xcp) - x_zotc(*xcp++); + x_zotc((unsigned char)*xcp++); } } @@ -2097,11 +2099,11 @@ x_fold_case(int c) */ if (cp != xep) { if (c == 'L') { /* lowercase */ - if (isupper(*cp)) - *cp = tolower(*cp); + if (isupper((unsigned char)*cp)) + *cp = tolower((unsigned char)*cp); } else { /* uppercase, capitalize */ - if (islower(*cp)) - *cp = toupper(*cp); + if (islower((unsigned char)*cp)) + *cp = toupper((unsigned char)*cp); } cp++; } @@ -2110,11 +2112,11 @@ x_fold_case(int c) */ while (cp != xep && !is_mfs(*cp)) { if (c == 'U') { /* uppercase */ - if (islower(*cp)) - *cp = toupper(*cp); + if (islower((unsigned char)*cp)) + *cp = toupper((unsigned char)*cp); } else { /* lowercase, capitalize */ - if (isupper(*cp)) - *cp = tolower(*cp); + if (isupper((unsigned char)*cp)) + *cp = tolower((unsigned char)*cp); } cp++; } @@ -2151,7 +2153,7 @@ x_lastcp(void) if (!xlp_valid) { for (i = 0, rcp = xbp; rcp < xep && i < x_displen; rcp++) - i += x_size(*rcp); + i += x_size((unsigned char)*rcp); xlp = rcp; } xlp_valid = true; diff --git a/bin/ksh/expr.c b/bin/ksh/expr.c index 857d3269c03..180842a20f3 100644 --- a/bin/ksh/expr.c +++ b/bin/ksh/expr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: expr.c,v 1.22 2013/03/28 08:39:28 nicm Exp $ */ +/* $OpenBSD: expr.c,v 1.23 2013/12/17 16:37:06 deraadt Exp $ */ /* * Korn expression evaluation @@ -463,7 +463,7 @@ token(Expr_state *es) char *tvar; /* skip white space */ - for (cp = es->tokp; (c = *cp), isspace(c); cp++) + for (cp = es->tokp; (c = *cp), isspace((unsigned char)c); cp++) ; es->tokp = cp; diff --git a/bin/ksh/io.c b/bin/ksh/io.c index ea2925cb8aa..93b2d822060 100644 --- a/bin/ksh/io.c +++ b/bin/ksh/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.22 2006/03/17 16:30:13 millert Exp $ */ +/* $OpenBSD: io.c,v 1.23 2013/12/17 16:37:06 deraadt Exp $ */ /* * shell buffered IO and formatted output @@ -293,7 +293,7 @@ check_fd(char *name, int mode, const char **emsgp) { int fd, fl; - if (isdigit(name[0]) && !name[1]) { + if (isdigit((unsigned char)name[0]) && !name[1]) { fd = name[0] - '0'; if ((fl = fcntl(fd = name[0] - '0', F_GETFL, 0)) < 0) { if (emsgp) diff --git a/bin/ksh/lex.c b/bin/ksh/lex.c index d0b6addd3d5..c27462e1876 100644 --- a/bin/ksh/lex.c +++ b/bin/ksh/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.48 2013/11/12 04:36:02 deraadt Exp $ */ +/* $OpenBSD: lex.c,v 1.49 2013/12/17 16:37:06 deraadt Exp $ */ /* * lexical analysis and source input @@ -986,7 +986,7 @@ getsc__(void) source->flags |= s->flags & SF_ALIAS; s = source; } else if (*s->u.tblp->val.s && - isspace(strchr(s->u.tblp->val.s, 0)[-1])) { + isspace((unsigned char)strchr(s->u.tblp->val.s, 0)[-1])) { source = s = s->next; /* pop source stack */ /* Note that this alias ended with a space, * enabling alias expansion on the following diff --git a/bin/ksh/var.c b/bin/ksh/var.c index d0c90ab6293..ac2bf76b875 100644 --- a/bin/ksh/var.c +++ b/bin/ksh/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.35 2013/04/05 01:31:30 tedu Exp $ */ +/* $OpenBSD: var.c,v 1.36 2013/12/17 16:37:06 deraadt Exp $ */ #include "sh.h" #include <time.h> @@ -166,7 +166,7 @@ global(const char *n) /* Check to see if this is an array */ n = array_index_calc(n, &array, &val); h = hash(n); - c = n[0]; + c = (unsigned char)n[0]; if (!letter(c)) { if (array) errorf("bad substitution"); @@ -442,7 +442,7 @@ getint(struct tbl *vp, long int *nump, bool arith) base = 8; have_base++; } - for (c = *s++; c ; c = *s++) { + for (c = (unsigned char)*s++; c ; c = (unsigned char)*s++) { if (c == '-') { neg++; } else if (c == '#') { @@ -518,7 +518,7 @@ formatstr(struct tbl *vp, const char *s) if (vp->flag & RJUST) { const char *q = s + olen; /* strip trailing spaces (at&t ksh uses q[-1] == ' ') */ - while (q > s && isspace(q[-1])) + while (q > s && isspace((unsigned char)q[-1])) --q; slen = q - s; if (slen > vp->u2.field) { @@ -531,7 +531,7 @@ formatstr(struct tbl *vp, const char *s) vp->u2.field - slen, null, slen, s); } else { /* strip leading spaces/zeros */ - while (isspace(*s)) + while (isspace((unsigned char)*s)) s++; if (vp->flag & ZEROFIL) while (*s == '0') @@ -544,12 +544,12 @@ formatstr(struct tbl *vp, const char *s) if (vp->flag & UCASEV_AL) { for (q = p; *q; q++) - if (islower(*q)) - *q = toupper(*q); + if (islower((unsigned char)*q)) + *q = toupper((unsigned char)*q); } else if (vp->flag & LCASEV) { for (q = p; *q; q++) - if (isupper(*q)) - *q = tolower(*q); + if (isupper((unsigned char)*q)) + *q = tolower((unsigned char)*q); } return p; diff --git a/bin/ksh/vi.c b/bin/ksh/vi.c index 889b35a8e6f..3cebffcf9e1 100644 --- a/bin/ksh/vi.c +++ b/bin/ksh/vi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vi.c,v 1.26 2009/06/29 22:50:19 martynas Exp $ */ +/* $OpenBSD: vi.c,v 1.27 2013/12/17 16:37:06 deraadt Exp $ */ /* * vi command editing @@ -197,7 +197,7 @@ x_vi(char *buf, size_t len) x_flush(); while (1) { if (macro.p) { - c = *macro.p++; + c = (unsigned char)*macro.p++; /* end of current macro? */ if (!c) { /* more macros left to finish? */ @@ -792,8 +792,9 @@ vi_cmd(int argcnt, const char *cmd) return -1; if (*cmd == 'c' && (cmd[1]=='w' || cmd[1]=='W') && - !isspace(es->cbuf[es->cursor])) { - while (isspace(es->cbuf[--ncursor])) + !isspace((unsigned char)es->cbuf[es->cursor])) { + while ((unsigned char) + isspace(es->cbuf[--ncursor])) ; ncursor++; } @@ -1032,7 +1033,7 @@ vi_cmd(int argcnt, const char *cmd) if (histnum(-1) < 0) return -1; p = *histpos(); -#define issp(c) (isspace((c)) || (c) == '\n') +#define issp(c) (isspace((unsigned char)(c)) || (c) == '\n') if (argcnt) { while (*p && issp(*p)) p++; @@ -1087,10 +1088,10 @@ vi_cmd(int argcnt, const char *cmd) return -1; for (i = 0; i < argcnt; i++) { p = &es->cbuf[es->cursor]; - if (islower(*p)) { + if (islower((unsigned char)*p)) { modified = 1; hnum = hlast; *p = toupper(*p); - } else if (isupper(*p)) { + } else if (isupper((unsigned char)*p)) { modified = 1; hnum = hlast; *p = tolower(*p); } @@ -1237,7 +1238,8 @@ domove(int argcnt, const char *cmd, int sub) case '^': ncursor = 0; - while (ncursor < es->linelen - 1 && isspace(es->cbuf[ncursor])) + while (ncursor < es->linelen - 1 && + isspace((unsigned char)es->cbuf[ncursor])) ncursor++; break; @@ -1519,12 +1521,13 @@ forwword(int argcnt) while (is_wordch(es->cbuf[ncursor]) && ncursor < es->linelen) ncursor++; - else if (!isspace(es->cbuf[ncursor])) + else if (!isspace((unsigned char)es->cbuf[ncursor])) while (!is_wordch(es->cbuf[ncursor]) && - !isspace(es->cbuf[ncursor]) && + !isspace((unsigned char)es->cbuf[ncursor]) && ncursor < es->linelen) ncursor++; - while (isspace(es->cbuf[ncursor]) && ncursor < es->linelen) + while (isspace((unsigned char)es->cbuf[ncursor]) && + ncursor < es->linelen) ncursor++; } return ncursor; @@ -1537,7 +1540,7 @@ backword(int argcnt) ncursor = es->cursor; while (ncursor > 0 && argcnt--) { - while (--ncursor > 0 && isspace(es->cbuf[ncursor])) + while (--ncursor > 0 && isspace((unsigned char)es->cbuf[ncursor])) ; if (ncursor > 0) { if (is_wordch(es->cbuf[ncursor])) @@ -1547,7 +1550,7 @@ backword(int argcnt) else while (--ncursor >= 0 && !is_wordch(es->cbuf[ncursor]) && - !isspace(es->cbuf[ncursor])) + !isspace((unsigned char)es->cbuf[ncursor])) ; ncursor++; } @@ -1563,7 +1566,7 @@ endword(int argcnt) ncursor = es->cursor; while (ncursor < es->linelen && argcnt--) { while (++ncursor < es->linelen - 1 && - isspace(es->cbuf[ncursor])) + isspace((unsigned char)es->cbuf[ncursor])) ; if (ncursor < es->linelen - 1) { if (is_wordch(es->cbuf[ncursor])) @@ -1573,7 +1576,7 @@ endword(int argcnt) else while (++ncursor < es->linelen && !is_wordch(es->cbuf[ncursor]) && - !isspace(es->cbuf[ncursor])) + !isspace((unsigned char)es->cbuf[ncursor])) ; ncursor--; } @@ -1588,9 +1591,11 @@ Forwword(int argcnt) ncursor = es->cursor; while (ncursor < es->linelen && argcnt--) { - while (!isspace(es->cbuf[ncursor]) && ncursor < es->linelen) + while (!isspace((unsigned char)es->cbuf[ncursor]) && + ncursor < es->linelen) ncursor++; - while (isspace(es->cbuf[ncursor]) && ncursor < es->linelen) + while (isspace((unsigned char)es->cbuf[ncursor]) && + ncursor < es->linelen) ncursor++; } return ncursor; @@ -1603,9 +1608,11 @@ Backword(int argcnt) ncursor = es->cursor; while (ncursor > 0 && argcnt--) { - while (--ncursor >= 0 && isspace(es->cbuf[ncursor])) + while (--ncursor >= 0 && + isspace((unsigned char)es->cbuf[ncursor])) ; - while (ncursor >= 0 && !isspace(es->cbuf[ncursor])) + while (ncursor >= 0 && + !isspace((unsigned char)es->cbuf[ncursor])) ncursor--; ncursor++; } @@ -1620,11 +1627,11 @@ Endword(int argcnt) ncursor = es->cursor; while (ncursor < es->linelen - 1 && argcnt--) { while (++ncursor < es->linelen - 1 && - isspace(es->cbuf[ncursor])) + isspace((unsigned char)es->cbuf[ncursor])) ; if (ncursor < es->linelen - 1) { while (++ncursor < es->linelen && - !isspace(es->cbuf[ncursor])) + !isspace((unsigned char)es->cbuf[ncursor])) ; ncursor--; } |