aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-09-28 23:02:57 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-09-28 23:02:57 +0200
commit8e2bc47d62d48687f681855d4b086c758ae745c4 (patch)
tree5666b8f66ea374d7a7716df9eda2f184f0749914
parent7ee7c6fc20d3b94c257f829dece097ff339895ee (diff)
downloadbusybox-w32-8e2bc47d62d48687f681855d4b086c758ae745c4.tar.gz
busybox-w32-8e2bc47d62d48687f681855d4b086c758ae745c4.tar.bz2
busybox-w32-8e2bc47d62d48687f681855d4b086c758ae745c4.zip
ash: [EVAL] Fix use-after-free in dotrap/evalstring
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>
-rw-r--r--shell/ash.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/shell/ash.c b/shell/ash.c
index f395a16a9..7a7ea1896 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1459,7 +1459,7 @@ stunalloc(void *p)
1459 * Like strdup but works with the ash stack. 1459 * Like strdup but works with the ash stack.
1460 */ 1460 */
1461static char * 1461static char *
1462ststrdup(const char *p) 1462sstrdup(const char *p)
1463{ 1463{
1464 size_t len = strlen(p) + 1; 1464 size_t len = strlen(p) + 1;
1465 return memcpy(stalloc(len), p, len); 1465 return memcpy(stalloc(len), p, len);
@@ -2514,7 +2514,7 @@ updatepwd(const char *dir)
2514 char *cdcomppath; 2514 char *cdcomppath;
2515 const char *lim; 2515 const char *lim;
2516 2516
2517 cdcomppath = ststrdup(dir); 2517 cdcomppath = sstrdup(dir);
2518 STARTSTACKSTR(new); 2518 STARTSTACKSTR(new);
2519 if (*dir != '/') { 2519 if (*dir != '/') {
2520 if (curdir == nullstr) 2520 if (curdir == nullstr)
@@ -6993,7 +6993,7 @@ addfname(const char *name)
6993 struct strlist *sp; 6993 struct strlist *sp;
6994 6994
6995 sp = stzalloc(sizeof(*sp)); 6995 sp = stzalloc(sizeof(*sp));
6996 sp->text = ststrdup(name); 6996 sp->text = sstrdup(name);
6997 *exparg.lastp = sp; 6997 *exparg.lastp = sp;
6998 exparg.lastp = &sp->next; 6998 exparg.lastp = &sp->next;
6999} 6999}
@@ -12221,10 +12221,12 @@ evalstring(char *s, int mask)
12221 int skip; 12221 int skip;
12222// int status; 12222// int status;
12223 12223
12224 s = sstrdup(s);
12224 setinputstring(s); 12225 setinputstring(s);
12225 setstackmark(&smark); 12226 setstackmark(&smark);
12226 12227
12227 skip = 0; 12228 skip = 0;
12229// status = 0;
12228 while ((n = parsecmd(0)) != NODE_EOF) { 12230 while ((n = parsecmd(0)) != NODE_EOF) {
12229 int i; 12231 int i;
12230 12232
@@ -12236,7 +12238,9 @@ evalstring(char *s, int mask)
12236 if (skip) 12238 if (skip)
12237 break; 12239 break;
12238 } 12240 }
12241 popstackmark(&smark);
12239 popfile(); 12242 popfile();
12243 stunalloc(s);
12240 12244
12241 skip &= mask; 12245 skip &= mask;
12242 evalskip = skip; 12246 evalskip = skip;