search for: popstackmark

Displaying 20 results from an estimated 23 matches for "popstackmark".

2020 Mar 28
0
[klibc:update-dash] dash: eval: avoid leaking memory associated with redirections
...nt flags) { int checkexit = 0; int (*evalfn)(union node *, int); + struct stackmark smark; unsigned isor; int status = 0; + + setstackmark(&smark); + if (n == NULL) { TRACE(("evaltree(NULL) called\n")); goto out; @@ -317,6 +321,8 @@ exexit: exraise(EXEXIT); } + popstackmark(&smark); + return exitstatus; } @@ -396,14 +402,12 @@ evalfor(union node *n, int flags) struct arglist arglist; union node *argp; struct strlist *sp; - struct stackmark smark; int status; errlinno = lineno = n->nfor.linno; if (funcline) lineno -= funcline - 1; - setst...
2019 Jan 25
0
[klibc:update-dash] eval: Return status in eval functions
...**, int); STATIC int evalfun(struct funcnode *, int, char **, int); @@ -170,11 +170,13 @@ evalstring(char *s, int flags) setstackmark(&smark); status = 0; - while ((n = parsecmd(0)) != NEOF) { - evaltree(n, flags & ~(parser_eof() ? 0 : EV_EXIT)); + for (; (n = parsecmd(0)) != NEOF; popstackmark(&smark)) { + int i; + + i = evaltree(n, flags & ~(parser_eof() ? 0 : EV_EXIT)); if (n) - status = exitstatus; - popstackmark(&smark); + status = i; + if (evalskip) break; } @@ -192,13 +194,13 @@ evalstring(char *s, int flags) * exitstatus. */ -void +int evaltre...
2020 Mar 28
0
[klibc:update-dash] dash: eval: Return status in eval functions
...**, int); STATIC int evalfun(struct funcnode *, int, char **, int); @@ -170,11 +170,13 @@ evalstring(char *s, int flags) setstackmark(&smark); status = 0; - while ((n = parsecmd(0)) != NEOF) { - evaltree(n, flags & ~(parser_eof() ? 0 : EV_EXIT)); + for (; (n = parsecmd(0)) != NEOF; popstackmark(&smark)) { + int i; + + i = evaltree(n, flags & ~(parser_eof() ? 0 : EV_EXIT)); if (n) - status = exitstatus; - popstackmark(&smark); + status = i; + if (evalskip) break; } @@ -192,13 +194,13 @@ evalstring(char *s, int flags) * exitstatus. */ -void +int evaltre...
2019 Jan 25
0
[klibc:update-dash] input: Fix here-document redirection with vi/emacs on
.... Nice find. The problem is that getprompt() is implicitly called by el_gets(). This messes with the memory used by the parser to store the here-document's contents. In the non-emacs/vi case, the prompt is explicitly written by setprompt(), which wraps the getprompt() call in a pushstackmark()/popstackmark() pair to restore the state so that parsing can continue. But when getprompt() is called by el_gets(), it knows nothing about this. The whole call to el_gets() can be surrounded by another pushstackmark()/popstackmark() pair to solve the problem, as attached. Cheers, Harald van Dijk Signed-off-b...
2020 Mar 28
0
[klibc:update-dash] dash: input: Fix here-document redirection with vi/emacs on
.... Nice find. The problem is that getprompt() is implicitly called by el_gets(). This messes with the memory used by the parser to store the here-document's contents. In the non-emacs/vi case, the prompt is explicitly written by setprompt(), which wraps the getprompt() call in a pushstackmark()/popstackmark() pair to restore the state so that parsing can continue. But when getprompt() is called by el_gets(), it knows nothing about this. The whole call to el_gets() can be surrounded by another pushstackmark()/popstackmark() pair to solve the problem, as attached. Cheers, Harald van Dijk Signed-off-b...
2020 Mar 28
0
[klibc:update-dash] dash: memalloc: Avoid looping in growstackto
....org.uk> --- usr/dash/memalloc.c | 16 ++++++++-------- usr/dash/memalloc.h | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/usr/dash/memalloc.c b/usr/dash/memalloc.c index 9d1de74a..60637da1 100644 --- a/usr/dash/memalloc.c +++ b/usr/dash/memalloc.c @@ -201,16 +201,16 @@ popstackmark(struct stackmark *mark) * part of the block that has been used. */ -void -growstackblock(void) +static void growstackblock(size_t min) { size_t newlen; newlen = stacknleft * 2; if (newlen < stacknleft) sh_error("Out of space"); - if (newlen < 128) - newlen += 128;...
2019 Jan 25
0
[klibc:update-dash] eval: Fix exit status when calling eval/dot with no commands
...index db7639a4..ef6ec0ef 100644 --- a/usr/dash/eval.c +++ b/usr/dash/eval.c @@ -172,7 +172,8 @@ evalstring(char *s, int flags) status = 0; while ((n = parsecmd(0)) != NEOF) { evaltree(n, flags & ~(parser_eof() ? 0 : EV_EXIT)); - status = exitstatus; + if (n) + status = exitstatus; popstackmark(&smark); if (evalskip) break; diff --git a/usr/dash/main.c b/usr/dash/main.c index bedb6635..497ac160 100644 --- a/usr/dash/main.c +++ b/usr/dash/main.c @@ -228,7 +228,8 @@ cmdloop(int top) job_warning = (job_warning == 2) ? 1 : 0; numeof = 0; evaltree(n, 0); - status = exi...
2020 Mar 28
0
[klibc:update-dash] dash: eval: Fix exit status when calling eval/dot with no commands
...index 3325cb62..0380d1d2 100644 --- a/usr/dash/eval.c +++ b/usr/dash/eval.c @@ -172,7 +172,8 @@ evalstring(char *s, int flags) status = 0; while ((n = parsecmd(0)) != NEOF) { evaltree(n, flags & ~(parser_eof() ? 0 : EV_EXIT)); - status = exitstatus; + if (n) + status = exitstatus; popstackmark(&smark); if (evalskip) break; diff --git a/usr/dash/main.c b/usr/dash/main.c index bedb6635..497ac160 100644 --- a/usr/dash/main.c +++ b/usr/dash/main.c @@ -228,7 +228,8 @@ cmdloop(int top) job_warning = (job_warning == 2) ? 1 : 0; numeof = 0; evaltree(n, 0); - status = exi...
2019 Jan 25
0
[klibc:update-dash] [BUILTIN] Handle embedded NULs correctly in printf
...stackblock(); + len = p - q; + + p = makestrspace(len, p); + memset(p, 'X', len - 1); + p[len - 1] = 0; + + q = stackblock(); + total = ASPF(&p, f, p); + + len = strchrnul(p, 'X') - p; + memcpy(p + len, q, strchrnul(p + len, ' ') - (p + len)); + + out1mem(p, total); + + popstackmark(&smark); + return done; +} + + int printfcmd(int argc, char *argv[]) { char *fmt; @@ -156,17 +203,14 @@ pc: fmt[1] = 0; switch (ch) { - case 'b': { - int done = conv_escape_str(getstr()); - char *p = stackblock(); + case 'b': *fmt = 's'; -...
2020 Mar 28
0
[klibc:update-dash] dash: [BUILTIN] Handle embedded NULs correctly in printf
...stackblock(); + len = p - q; + + p = makestrspace(len, p); + memset(p, 'X', len - 1); + p[len - 1] = 0; + + q = stackblock(); + total = ASPF(&p, f, p); + + len = strchrnul(p, 'X') - p; + memcpy(p + len, q, strchrnul(p + len, ' ') - (p + len)); + + out1mem(p, total); + + popstackmark(&smark); + return done; +} + + int printfcmd(int argc, char *argv[]) { char *fmt; @@ -156,17 +203,14 @@ pc: fmt[1] = 0; switch (ch) { - case 'b': { - int done = conv_escape_str(getstr()); - char *p = stackblock(); + case 'b': *fmt = 's'; -...
2019 Jan 25
0
[klibc:update-dash] [EVAL] Fix use-after-free in dotrap/evalstring
...2 100644 --- a/usr/dash/eval.c +++ b/usr/dash/eval.c @@ -160,6 +160,7 @@ evalstring(char *s, int flags) struct stackmark smark; int status; + s = sstrdup(s); setinputstring(s); setstackmark(&smark); @@ -171,7 +172,9 @@ evalstring(char *s, int flags) if (evalskip) break; } + popstackmark(&smark); popfile(); + stunalloc(s); return status; } diff --git a/usr/dash/histedit.c b/usr/dash/histedit.c index b27d6294..94465d78 100644 --- a/usr/dash/histedit.c +++ b/usr/dash/histedit.c @@ -372,8 +372,7 @@ histcmd(int argc, char **argv) out2str(s); } - evalstring(st...
2019 Jan 25
0
[klibc:update-dash] [EVAL] Move common skipcount logic into skiploop
...;nfor.body, flags); - if (evalskip) { - if (evalskip == SKIPCONT && --skipcount <= 0) { - evalskip = 0; - continue; - } - if (evalskip == SKIPBREAK && --skipcount <= 0) - evalskip = 0; + if (skiploop() & ~SKIPCONT) break; - } } loopnest--; -out: popstackmark(&smark); }
2019 Jan 25
0
[klibc:update-dash] builtin: Fix echo performance regression
...); + memset(p, 'X', total); + p[total] = 0; q = stackblock(); total = ASPF(&p, f, p); len = strchrnul(p, 'X') - p; - memcpy(p + len, q, strchrnul(p + len, ' ') - (p + len)); + memcpy(p + len, q, strspn(p + len, "X")); +easy: out1mem(p, total); popstackmark(&smark);
2020 Mar 28
0
[klibc:update-dash] dash: [EVAL] Fix use-after-free in dotrap/evalstring
...e 100644 --- a/usr/dash/eval.c +++ b/usr/dash/eval.c @@ -160,6 +160,7 @@ evalstring(char *s, int flags) struct stackmark smark; int status; + s = sstrdup(s); setinputstring(s); setstackmark(&smark); @@ -171,7 +172,9 @@ evalstring(char *s, int flags) if (evalskip) break; } + popstackmark(&smark); popfile(); + stunalloc(s); return status; } diff --git a/usr/dash/histedit.c b/usr/dash/histedit.c index b27d6294..94465d78 100644 --- a/usr/dash/histedit.c +++ b/usr/dash/histedit.c @@ -372,8 +372,7 @@ histcmd(int argc, char **argv) out2str(s); } - evalstring(st...
2020 Mar 28
0
[klibc:update-dash] dash: builtin: Fix echo performance regression
...); + memset(p, 'X', total); + p[total] = 0; q = stackblock(); total = ASPF(&p, f, p); len = strchrnul(p, 'X') - p; - memcpy(p + len, q, strchrnul(p + len, ' ') - (p + len)); + memcpy(p + len, q, strspn(p + len, "X")); +easy: out1mem(p, total); popstackmark(&smark);
2020 Mar 28
0
[klibc:update-dash] dash: [EVAL] Move common skipcount logic into skiploop
...;nfor.body, flags); - if (evalskip) { - if (evalskip == SKIPCONT && --skipcount <= 0) { - evalskip = 0; - continue; - } - if (evalskip == SKIPBREAK && --skipcount <= 0) - evalskip = 0; + if (skiploop() & ~SKIPCONT) break; - } } loopnest--; -out: popstackmark(&smark); }
2020 Mar 28
0
[klibc:update-dash] dash: memalloc: Add growstackto helper
...kblock(); - } - return stackblock() + len; + return growstackto(len + newlen) + len; } char * diff --git a/usr/dash/memalloc.h b/usr/dash/memalloc.h index 4b5be46c..b348d9cc 100644 --- a/usr/dash/memalloc.h +++ b/usr/dash/memalloc.h @@ -57,6 +57,7 @@ void setstackmark(struct stackmark *); void popstackmark(struct stackmark *); void growstackblock(void); void *growstackstr(void); +char *growstackto(size_t len); char *makestrspace(size_t, char *); char *stnputs(const char *, size_t, char *); char *stputs(const char *, char *); diff --git a/usr/dash/parser.c b/usr/dash/parser.c index 809c6a8a..3de9...
2020 Mar 28
0
[klibc:update-dash] dash: expand: Do not reprocess data when expanding words
...doff = expdest - start; + start += begoff; + STADJUST(start - expdest, expdest); removerecordregions(begoff); - expdest = p; - if (likely(flag & QUOTES_ESC)) - rmescapes(p + 1); + rmescapes(start); - result = arith(p + 1); + pushstackmark(&sm, endoff); + result = arith(start); popstackmark(&sm); len = cvtnum(result); if (likely(!(flag & EXP_QUOTED))) recordregion(begoff, begoff + len, 0); + +out: + return p; } @@ -512,6 +488,9 @@ expbackq(union node *cmd, int flag) int startloc; struct stackmark smark; + if (flag & EXP_DISCARD) + goto out; + INTOF...
2020 Mar 28
0
[klibc:update-dash] dash: eval: Only restore exit status on exit/return
...= 0) { - exitstatus = savestatus; + if (exception == EXEXIT || evalskip == SKIPFUNCDEF) + exitstatus = savestatus; savestatus = -1; } + evalskip = 0; + loopnest = 0; } #endif @@ -318,7 +319,7 @@ out: if (flags & EV_EXIT) { exexit: - exraise(EXEXIT); + exraise(EXEND); } popstackmark(&smark); diff --git a/usr/dash/exec.c b/usr/dash/exec.c index 9d0215a6..87354d49 100644 --- a/usr/dash/exec.c +++ b/usr/dash/exec.c @@ -143,7 +143,7 @@ shellexec(char **argv, const char *path, int idx) exitstatus = exerrno; TRACE(("shellexec failed for %s, errno %d, suppressint %d\n&qu...
2020 Mar 28
0
[klibc:update-dash] dash: expand: Ensure result is escaped in cvtnum
...intmax_t num, int flags); STATIC size_t esclen(const char *, const char *); STATIC char *scanleft(char *, char *, char *, char *, int, int); STATIC char *scanright(char *, char *, char *, char *, int, int); @@ -463,7 +463,7 @@ static char *expari(char *start, int flag) result = arith(start); popstackmark(&sm); - len = cvtnum(result); + len = cvtnum(result, flag); if (likely(!(flag & EXP_QUOTED))) recordregion(begoff, begoff + len, 0); @@ -746,7 +746,7 @@ again: if (subtype == VSLENGTH) { if (flag & EXP_DISCARD) return p; - cvtnum(varlen > 0 ? varlen : 0); + cvtnum...