From upstream:
[EVAL] Fix use-after-free in dotrap/evalstring
The function dotrap calls evalstring using the stored trap string.
If evalstring then unsets that exact trap string then we will end
up using freed memory.
This patch fixes it by making evalstring always duplicate the string
before using it.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Like strdup but works with the ash stack.
*/
static char *
-ststrdup(const char *p)
+sstrdup(const char *p)
{
size_t len = strlen(p) + 1;
return memcpy(stalloc(len), p, len);
char *cdcomppath;
const char *lim;
- cdcomppath = ststrdup(dir);
+ cdcomppath = sstrdup(dir);
STARTSTACKSTR(new);
if (*dir != '/') {
if (curdir == nullstr)
struct strlist *sp;
sp = stzalloc(sizeof(*sp));
- sp->text = ststrdup(name);
+ sp->text = sstrdup(name);
*exparg.lastp = sp;
exparg.lastp = &sp->next;
}
int skip;
// int status;
+ s = sstrdup(s);
setinputstring(s);
setstackmark(&smark);
skip = 0;
+// status = 0;
while ((n = parsecmd(0)) != NODE_EOF) {
int i;
if (skip)
break;
}
+ popstackmark(&smark);
popfile();
+ stunalloc(s);
skip &= mask;
evalskip = skip;