Import OpenBSD source tree of short before 17:00 UTC today

This commit is contained in:
tg
2003-05-07 17:15:23 +00:00
parent 93aa08df64
commit 7ebc0530d6
8 changed files with 54 additions and 47 deletions

34
eval.c
View File

@ -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;