fix attempt to free pointer to stack (function-local storage)

discovered by Elias Pipping
patch by Jared Yanovich
alloc/afree checker by Todd C. Miller
This commit is contained in:
tg 2008-07-14 12:29:06 +00:00
parent a9f219dd60
commit 5f0269ed9a
4 changed files with 24 additions and 11 deletions

16
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.215 2008/07/12 18:09:36 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.216 2008/07/14 12:29:04 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R35 2008/07/12
@(#)MIRBSD KSH R35 2008/07/14
description:
Check version of shell.
stdin:
@ -3843,6 +3843,18 @@ expected-stdout:
FNORD_H=8
FNORD-8
---
name: regression-64
description:
Check that we can redefine functions calling time builtin
stdin:
t() {
time >/dev/null
}
t 2>/dev/null
t() {
time
}
---
name: syntax-1
description:
Check that lone ampersand is a syntax error

View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.84 2008/07/12 16:56:39 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.85 2008/07/14 12:29:05 tg Exp $");
/* A leading = means assignments before command are kept;
* a leading * means a POSIX special builtin;
@ -2209,7 +2209,6 @@ timex(struct op *t, int f)
int rv = 0, tf = 0;
struct rusage ru0, ru1, cru0, cru1;
struct timeval usrtime, systime, tv0, tv1;
char opts[1];
gettimeofday(&tv0, NULL);
getrusage(RUSAGE_SELF, &ru0);
@ -2225,11 +2224,8 @@ 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];
tf |= t->left->str[0];
gettimeofday(&tv1, NULL);
getrusage(RUSAGE_SELF, &ru1);
getrusage(RUSAGE_CHILDREN, &cru1);

4
sh.h
View File

@ -100,9 +100,9 @@
#define __SCCSID(x) __IDSTRING(sccsid,x)
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.227 2008/07/12 18:09:37 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.228 2008/07/14 12:29:06 tg Exp $");
#endif
#define MKSH_VERSION "R35 2008/07/12"
#define MKSH_VERSION "R35 2008/07/14"
#ifndef MKSH_INCLUDES_ONLY

7
syn.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.23 2008/07/12 16:56:40 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.24 2008/07/14 12:29:06 tg Exp $");
struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */
@ -411,6 +411,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;