diff options
author | Thierry Deval <tdeval@cvs.openbsd.org> | 2003-04-16 23:11:53 +0000 |
---|---|---|
committer | Thierry Deval <tdeval@cvs.openbsd.org> | 2003-04-16 23:11:53 +0000 |
commit | 5e8530d18d562483353cc7c40db2db516e42ae99 (patch) | |
tree | 73786f63509f15358123d0b1b34e7a9b5194a0fa | |
parent | fabf32e0c7ec1d169c392dd43d1c252d6d6cec17 (diff) |
string cleaning. ok tedu@
-rw-r--r-- | bin/ksh/emacs.c | 8 | ||||
-rw-r--r-- | bin/ksh/eval.c | 34 | ||||
-rw-r--r-- | bin/ksh/misc.c | 4 | ||||
-rw-r--r-- | bin/ksh/proto.h | 4 | ||||
-rw-r--r-- | bin/ksh/var.c | 7 |
5 files changed, 32 insertions, 25 deletions
diff --git a/bin/ksh/emacs.c b/bin/ksh/emacs.c index feaeb7f9159..392b0246fe1 100644 --- a/bin/ksh/emacs.c +++ b/bin/ksh/emacs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: emacs.c,v 1.18 2003/02/28 09:45:09 jmc Exp $ */ +/* $OpenBSD: emacs.c,v 1.19 2003/04/16 23:11:52 tdeval Exp $ */ /* * Emacs-like command line editing and history @@ -886,9 +886,9 @@ x_load_hist(hp) } x_histp = hp; oldsize = x_size_str(xbuf); - (void)strcpy(xbuf, *hp); + strlcpy(xbuf, *hp, xend - xbuf); xbp = xbuf; - xep = xcp = xbuf + strlen(*hp); + xep = xcp = xbuf + strlen(xbuf); xlp_valid = FALSE; if (xep > x_lastcp()) x_goto(xep); @@ -1022,7 +1022,7 @@ x_del_line(c) int i, j; *xep = 0; - i = xep- xbuf; + i = xep - xbuf; j = x_size_str(xbuf); xcp = xbuf; x_push(i); diff --git a/bin/ksh/eval.c b/bin/ksh/eval.c index 2a0990ae26e..8f998cf2283 100644 --- a/bin/ksh/eval.c +++ b/bin/ksh/eval.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eval.c,v 1.12 2003/03/10 03:48:16 david Exp $ */ +/* $OpenBSD: eval.c,v 1.13 2003/04/16 23:11:52 tdeval Exp $ */ /* * Expansion - quoting, separation, substitution, globbing @@ -175,6 +175,7 @@ expand(cp, wp, f) int UNINITIALIZED(newlines); /* For trailing newlines in COMSUB */ int saw_eq, tilde_ok; int make_magic; + size_t len; if (cp == NULL) internal_errorf(1, "expand(NULL)"); @@ -415,10 +416,11 @@ expand(cp, wp, f) * fatal for special builtins (setstr * does readonly check). */ - setstr(st->var, debunk( - (char *) alloc(strlen(dp) + 1, - ATEMP), dp), - KSH_UNWIND_ERROR); + len = strlen(dp) + 1; + setstr(st->var, + debunk((char *) alloc(len, ATEMP), + dp, len), + KSH_UNWIND_ERROR); x.str = str_val(st->var); type = XSUB; if (f&DOBLANK) @@ -432,7 +434,7 @@ expand(cp, wp, f) errorf("%s: %s", st->var->name, dp == s ? "parameter null or not set" - : (debunk(s, s), s)); + : (debunk(s, s, strlen(s) + 1), s)); } } st = st->prev; @@ -576,7 +578,7 @@ expand(cp, wp, f) else if ((f & DOPAT) || !(fdo & DOMAGIC_)) XPput(*wp, p); else - XPput(*wp, debunk(p, p)); + XPput(*wp, debunk(p, p, strlen(p) + 1)); fdo = 0; saw_eq = 0; tilde_ok = (f & (DOTILDE|DOASNTILDE)) ? 1 : 0; @@ -950,7 +952,7 @@ glob(cp, wp, markdirs) int oldsize = XPsize(*wp); if (glob_str(cp, wp, markdirs) == 0) - XPput(*wp, debunk(cp, cp)); + XPput(*wp, debunk(cp, cp, strlen(cp) + 1)); else qsortp(XPptrv(*wp) + oldsize, (size_t)(XPsize(*wp) - oldsize), xstrcmp); @@ -1085,7 +1087,7 @@ globit(xs, xpp, sp, wp, check) */ if (!has_globbing(sp, se)) { XcheckN(*xs, xp, se - sp + 1); - debunk(xp, sp); + debunk(xp, sp, Xnleft(*xs, xp)); xp += strlen(xp); *xpp = xp; globit(xs, xpp, np, wp, check); @@ -1174,15 +1176,18 @@ copy_non_glob(xs, xpp, p) /* remove MAGIC from string */ char * -debunk(dp, sp) +debunk(dp, sp, dlen) char *dp; const char *sp; + size_t dlen; { char *d, *s; if ((s = strchr(sp, MAGIC))) { + if (s - sp >= dlen) + return dp; memcpy(dp, sp, s - sp); - for (d = dp + (s - sp); *s; s++) + for (d = dp + (s - sp); *s && (d - dp < dlen); s++) if (!ISMAGIC(*s) || !(*++s & 0x80) || !strchr("*+?@! ", *s & 0x7f)) *d++ = *s; @@ -1190,11 +1195,12 @@ debunk(dp, sp) /* extended pattern operators: *+?@! */ if ((*s & 0x7f) != ' ') *d++ = *s & 0x7f; - *d++ = '('; + if (d - dp < dlen) + *d++ = '('; } *d = '\0'; } else if (dp != sp) - strcpy(dp, sp); + strlcpy(dp, sp, dlen); return dp; } @@ -1337,7 +1343,7 @@ alt_expand(wp, start, exp_start, end, fdo) if (fdo & DOGLOB) glob(start, wp, fdo & DOMARKDIRS); else - XPput(*wp, debunk(start, start)); + XPput(*wp, debunk(start, start, end - start)); return; } brace_end = p; diff --git a/bin/ksh/misc.c b/bin/ksh/misc.c index bf0149591bf..dbbc22268e0 100644 --- a/bin/ksh/misc.c +++ b/bin/ksh/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.15 2003/04/04 23:12:02 deraadt Exp $ */ +/* $OpenBSD: misc.c,v 1.16 2003/04/16 23:11:52 tdeval Exp $ */ /* * Miscellaneous functions @@ -542,7 +542,7 @@ gmatch(s, p, isfile) char tbuf[64]; char *t = len <= sizeof(tbuf) ? tbuf : (char *) alloc(len, ATEMP); - debunk(t, p); + debunk(t, p, len); return !strcmp(t, s); } return do_gmatch((const unsigned char *) s, (const unsigned char *) se, diff --git a/bin/ksh/proto.h b/bin/ksh/proto.h index 7a7c9a80dcb..42a0427aa50 100644 --- a/bin/ksh/proto.h +++ b/bin/ksh/proto.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proto.h,v 1.9 2001/02/19 09:49:54 camield Exp $ */ +/* $OpenBSD: proto.h,v 1.10 2003/04/16 23:11:52 tdeval Exp $ */ /* * prototypes for PD-KSH @@ -62,7 +62,7 @@ char * substitute ARGS((const char *cp, int f)); char ** eval ARGS((char **ap, int f)); char * evalstr ARGS((char *cp, int f)); char * evalonestr ARGS((char *cp, int f)); -char *debunk ARGS((char *dp, const char *sp)); +char *debunk ARGS((char *dp, const char *sp, size_t dlen)); void expand ARGS((char *cp, XPtrV *wp, int f)); int glob_str ARGS((char *cp, XPtrV *wp, int markdirs)); /* exec.c */ diff --git a/bin/ksh/var.c b/bin/ksh/var.c index 98faa2cacc4..b6ee7ebf009 100644 --- a/bin/ksh/var.c +++ b/bin/ksh/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.13 2003/03/13 09:03:07 deraadt Exp $ */ +/* $OpenBSD: var.c,v 1.14 2003/04/16 23:11:52 tdeval Exp $ */ #include "sh.h" #include "ksh_time.h" @@ -1132,6 +1132,7 @@ arraysearch(vp, val) int val; { struct tbl *prev, *curr, *new; + size_t namelen = strlen(vp->name) + 1; vp->flag |= ARRAY|DEFINED; @@ -1152,9 +1153,9 @@ arraysearch(vp, val) else new = curr; } else - new = (struct tbl *)alloc(sizeof(struct tbl)+strlen(vp->name)+1, + new = (struct tbl *)alloc(sizeof(struct tbl) + namelen, vp->areap); - strcpy(new->name, vp->name); + strlcpy(new->name, vp->name, namelen); new->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL); new->type = vp->type; new->areap = vp->areap; |