OpenBSD found out that "building argv for $* and $@" manipulates l->argv

in place which affects ps(1) output on BSD; create a new array and copy
the original parts from argv[] there without touching argv passed to main
This commit is contained in:
tg
2012-09-07 21:02:43 +00:00
parent 0415b74436
commit eac85ffdf1
3 changed files with 16 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.557 2012/09/01 23:46:39 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.558 2012/09/07 21:02:40 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 $
@@ -29,7 +29,7 @@
# http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD
expected-stdout:
@(#)MIRBSD KSH R40 2012/09/01
@(#)MIRBSD KSH R40 2012/09/07
description:
Check version of shell.
stdin:
@@ -38,7 +38,7 @@ name: KSH_VERSION
category: shell:legacy-no
---
expected-stdout:
@(#)LEGACY KSH R40 2012/09/01
@(#)LEGACY KSH R40 2012/09/07
description:
Check version of legacy shell.
stdin:

14
main.c
View File

@@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.47 2011/09/07 11:33:25 otto Exp $ */
/* $OpenBSD: main.c,v 1.50 2012/09/06 18:04:34 millert Exp $ */
/* $OpenBSD: tty.c,v 1.9 2006/03/14 22:08:01 deraadt Exp $ */
/* $OpenBSD: io.c,v 1.22 2006/03/17 16:30:13 millert Exp $ */
/* $OpenBSD: table.c,v 1.15 2012/02/19 07:52:30 otto Exp $ */
@@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.226 2012/07/22 15:56:50 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.227 2012/09/07 21:02:43 tg Exp $");
extern char **environ;
@@ -537,8 +537,16 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
l->argv[0] = ccp;
} else {
l->argc = argc - argi;
l->argv = &argv[argi - 1];
/*
* allocate a new array because otherwise, when we modify
* it in-place, ps(1) output changes; the meaning of argc
* here is slightly different as it excludes kshname, and
* we add a trailing NULL sentinel as well
*/
l->argv = alloc2(l->argc + 2, sizeof(void *), APERM);
l->argv[0] = kshname;
memcpy(&l->argv[1], &argv[argi], l->argc * sizeof(void *));
l->argv[l->argc + 1] = NULL;
getopts_reset(1);
}

4
sh.h
View File

@@ -157,9 +157,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.585 2012/09/01 23:46:41 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.586 2012/09/07 21:02:43 tg Exp $");
#endif
#define MKSH_VERSION "R40 2012/09/01"
#define MKSH_VERSION "R40 2012/09/07"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES