Re: patchset to optionally disable function exports

2014-10-13 Thread Chet Ramey
On 9/25/14, 4:37 PM, David Galos wrote:
 I understand that some people might find function exports useful, but
 there is also some utility in being able to turn it off.

I will probably include some variant of this in the next release of bash.
Thanks for the report and patches.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



patchset to optionally disable function exports

2014-09-25 Thread David Galos
I understand that some people might find function exports useful, but
there is also some utility in being able to turn it off.

I've added a configure flag, --disable-function-export which prevents
bash from attempting to parse environment variables that look like
functions upon startup. The default behavior is still to allow
function exports. You can note that this actually adds symmetry with
array exports for which there is already a flag that does the same
thing.

Let me know if there is interest in this, or what I might need to do
further to get this accepted.


Thanks,
Dave
From 9f8f691304329618556c8c33dfc0b30cd10fcf26 Mon Sep 17 00:00:00 2001
From: David Galos davega...@google.com
Date: Thu, 25 Sep 2014 13:27:43 -0400
Subject: [PATCH 1/4] add a flag to enable or disable function import on
 startup

---
 configure.in | 6 ++
 variables.c  | 4 
 2 files changed, 10 insertions(+)

diff --git a/configure.in b/configure.in
index d7e0998..c48bf07 100644
--- a/configure.in
+++ b/configure.in
@@ -186,6 +186,7 @@ opt_single_longdoc_strings=yes
 opt_casemod_attrs=yes
 opt_casemod_expansions=yes
 opt_extglob_default=no
+opt_function_export=yes
 
 dnl options that affect how bash is compiled and linked
 opt_static_link=no
@@ -206,6 +207,7 @@ if test $opt_minimal_config = yes; then
 	opt_net_redirs=no opt_progcomp=no opt_separate_help=no
 	opt_multibyte=yes opt_cond_regexp=no opt_coproc=no
 	opt_casemod_attrs=no opt_casemod_expansions=no opt_extglob_default=no
+	opt_function_export=no
 fi
 
 AC_ARG_ENABLE(alias, AC_HELP_STRING([--enable-alias], [enable shell aliases]), opt_alias=$enableval)
@@ -241,6 +243,7 @@ AC_ARG_ENABLE(single-help-strings, AC_HELP_STRING([--enable-single-help-strings]
 AC_ARG_ENABLE(strict-posix-default, AC_HELP_STRING([--enable-strict-posix-default], [configure bash to be posix-conformant by default]), opt_strict_posix=$enableval)
 AC_ARG_ENABLE(usg-echo-default, AC_HELP_STRING([--enable-usg-echo-default], [a synonym for --enable-xpg-echo-default]), opt_xpg_echo=$enableval)
 AC_ARG_ENABLE(xpg-echo-default, AC_HELP_STRING([--enable-xpg-echo-default], [make the echo builtin expand escape sequences by default]), opt_xpg_echo=$enableval)
+AC_ARG_ENABLE(function-export, AC_HELP_STRING([--enable-function-export], [allow bash to treat certain environment variables as functions]), opt_function_export=$enableval)
 
 dnl options that alter how bash is compiled and linked
 AC_ARG_ENABLE(mem-scramble, AC_HELP_STRING([--enable-mem-scramble], [scramble memory on calls to malloc and free]), opt_memscramble=$enableval)
@@ -333,6 +336,9 @@ fi
 if test $opt_casemod_expansions = yes; then
 AC_DEFINE(CASEMOD_EXPANSIONS)
 fi
+if test $opt_function_export = yes; then
+AC_DEFINE(FUNCTION_EXPORT)
+fi
 
 if test $opt_memscramble = yes; then
 AC_DEFINE(MEMSCRAMBLE)
diff --git a/variables.c b/variables.c
index 92a5a10..f33f66c 100644
--- a/variables.c
+++ b/variables.c
@@ -349,7 +349,11 @@ initialize_shell_variables (env, privmode)
 
   /* If exported function, define it now.  Don't import functions from
 	 the environment in privileged mode. */
+#if defined (FUNCTION_EXPORT)
   if (privmode == 0  read_but_dont_execute == 0  STREQN (() {, string, 4))
+#else
+  if (0)
+#endif
 	{
 	  string_length = strlen (string);
 	  temp_string = (char *)xmalloc (3 + string_length + char_index);
-- 
2.1.0.rc2.206.gedb03e5

From 0f6618bfd1a714b10205b20bb682e4de21a2a7f0 Mon Sep 17 00:00:00 2001
From: David Galos davega...@google.com
Date: Thu, 25 Sep 2014 13:41:35 -0400
Subject: [PATCH 2/4] merge configure.in changes to configure.ac

---
 configure.ac | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 97e8e04..2b116f8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -193,6 +193,7 @@ opt_casemod_expansions=yes
 opt_extglob_default=no
 opt_dircomplete_expand_default=no
 opt_globascii_default=no
+opt_function_export=yes
 
 dnl options that affect how bash is compiled and linked
 opt_static_link=no
@@ -213,7 +214,7 @@ if test $opt_minimal_config = yes; then
 	opt_net_redirs=no opt_progcomp=no opt_separate_help=no
 	opt_multibyte=yes opt_cond_regexp=no opt_coproc=no
 	opt_casemod_attrs=no opt_casemod_expansions=no opt_extglob_default=no
-	opt_globascii_default=no
+	opt_globascii_default=no opt_function_export=no
 fi
 
 AC_ARG_ENABLE(alias, AC_HELP_STRING([--enable-alias], [enable shell aliases]), opt_alias=$enableval)
@@ -251,6 +252,7 @@ AC_ARG_ENABLE(single-help-strings, AC_HELP_STRING([--enable-single-help-strings]
 AC_ARG_ENABLE(strict-posix-default, AC_HELP_STRING([--enable-strict-posix-default], [configure bash to be posix-conformant by default]), opt_strict_posix=$enableval)
 AC_ARG_ENABLE(usg-echo-default, AC_HELP_STRING([--enable-usg-echo-default], [a synonym for --enable-xpg-echo-default]), opt_xpg_echo=$enableval)
 AC_ARG_ENABLE(xpg-echo-default, AC_HELP_STRING([--enable-xpg-echo-default], [make the echo builtin expand escape sequences by default]),