fix stack abuse in the `time' commmand, using alloc()'d memory instead.
authorjaredy <jaredy@openbsd.org>
Wed, 23 Jul 2008 16:34:38 +0000 (16:34 +0000)
committerjaredy <jaredy@openbsd.org>
Wed, 23 Jul 2008 16:34:38 +0000 (16:34 +0000)
reported by Thorsten Glaser, thanks.

ok millert@, earlier version miod@

bin/ksh/c_sh.c
bin/ksh/syn.c

index 901e206..ae5c3cd 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: c_sh.c,v 1.37 2007/09/03 13:54:23 otto Exp $  */
+/*     $OpenBSD: c_sh.c,v 1.38 2008/07/23 16:34:38 jaredy Exp $        */
 
 /*
  * built-in Bourne commands
@@ -719,7 +719,6 @@ timex(struct op *t, int f)
        struct timeval usrtime, systime, tv0, tv1;
        int tf = 0;
        extern struct timeval j_usrtime, j_systime; /* computed by j_wait */
-       char opts[1];
 
        gettimeofday(&tv0, NULL);
        getrusage(RUSAGE_SELF, &ru0);
@@ -735,11 +734,9 @@ timex(struct op *t, int f)
                 */
                timerclear(&j_usrtime);
                timerclear(&j_systime);
-               if (t->left->type == TCOM)
-                       t->left->str = opts;
-               opts[0] = 0;
                rv = execute(t->left, f | XTIME);
-               tf |= opts[0];
+               if (t->left->type == TCOM)
+                       tf |= t->left->str[0];
                gettimeofday(&tv1, NULL);
                getrusage(RUSAGE_SELF, &ru1);
                getrusage(RUSAGE_CHILDREN, &cru1);
index dc1d49e..9b7451a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: syn.c,v 1.27 2006/04/10 14:38:59 jaredy Exp $ */
+/*     $OpenBSD: syn.c,v 1.28 2008/07/23 16:34:38 jaredy Exp $ */
 
 /*
  * shell parser (C version)
@@ -364,6 +364,11 @@ get_command(int cf)
        case TIME:
                syniocf &= ~(KEYWORD|ALIAS);
                t = pipeline(0);
+               if (t) {
+                       t->str = alloc(2, ATEMP);
+                       t->str[0] = '\0'; /* TF_* flags */
+                       t->str[1] = '\0';
+               }
                t = block(TTIME, t, NOBLOCK, NOWORDS);
                break;