Skip to content

Instantly share code, notes, and snippets.

@slowriot
Created September 27, 2014 22:11
Show Gist options
  • Save slowriot/ed8d14b9d8eab68b5d12 to your computer and use it in GitHub Desktop.
Save slowriot/ed8d14b9d8eab68b5d12 to your computer and use it in GitHub Desktop.
Bash patch 2014-09-27 against 4.3.25(1)
diff -ur ../bash-4.3orig/parse.y ./parse.y
--- ../bash-4.3orig/parse.y 2014-09-27 17:52:38.878472141 -0400
+++ ./parse.y 2014-09-26 09:48:04.192597937 -0400
@@ -2953,6 +2953,8 @@
FREE (word_desc_to_read);
word_desc_to_read = (WORD_DESC *)NULL;
+ eol_ungetc_lookahead = 0;
+
current_token = '\n'; /* XXX */
last_read_token = '\n';
token_to_read = '\n';
diff -ur ../bash-4.3orig/variables.c ./variables.c
--- ../bash-4.3orig/variables.c 2014-09-27 17:52:38.892472141 -0400
+++ ./variables.c 2014-09-27 17:20:29.174472773 -0400
@@ -279,7 +279,7 @@
static void propagate_temp_var __P((PTR_T));
static void dispose_temporary_env __P((sh_free_func_t *));
-static inline char *mk_env_string __P((const char *, const char *));
+static inline char *mk_env_string __P((const char *, const char *, int));
static char **make_env_array_from_var_list __P((SHELL_VAR **));
static char **make_var_export_array __P((VAR_CONTEXT *));
static char **make_func_export_array __P((void));
@@ -312,6 +312,14 @@
#endif
}
+/* Prefix and suffix for environment variable names which contain
+ shell functions. */
+#define FUNCDEF_PREFIX "BASH_FUNC_"
+#define FUNCDEF_PREFIX_LEN (strlen (FUNCDEF_PREFIX))
+#define FUNCDEF_SUFFIX "()"
+#define FUNCDEF_SUFFIX_LEN (strlen (FUNCDEF_SUFFIX))
+
+
/* Initialize the shell variables from the current environment.
If PRIVMODE is nonzero, don't import functions from ENV or
parse $SHELLOPTS. */
@@ -2954,7 +2962,7 @@
var->context = variable_context; /* XXX */
INVALIDATE_EXPORTSTR (var);
- var->exportstr = mk_env_string (name, value);
+ var->exportstr = mk_env_string (name, value, 0);
array_needs_making = 1;
@@ -3851,22 +3859,43 @@
/* */
/* **************************************************************** */
+/* Returns the string NAME=VALUE if !FUNCTIONP or if VALUE == NULL (in
+ which case it is treated as empty). Otherwise, decorate NAME with
+ FUNCDEF_PREFIX and FUNCDEF_SUFFIX, and return a string of the form
+ FUNCDEF_PREFIX NAME FUNCDEF_SUFFIX = VALUE (without spaces). */
static inline char *
-mk_env_string (name, value)
+mk_env_string (name, value, functionp)
const char *name, *value;
+ int functionp;
{
- int name_len, value_len;
- char *p;
+ size_t name_len, value_len;
+ char *p, *q;
name_len = strlen (name);
value_len = STRLEN (value);
- p = (char *)xmalloc (2 + name_len + value_len);
- strcpy (p, name);
- p[name_len] = '=';
+ if (functionp && value != NULL)
+ {
+ p = (char *)xmalloc (FUNCDEF_PREFIX_LEN + name_len + FUNCDEF_SUFFIX_LEN
+ + 1 + value_len + 1);
+ q = p;
+ memcpy (q, FUNCDEF_PREFIX, FUNCDEF_PREFIX_LEN);
+ q += FUNCDEF_PREFIX_LEN;
+ memcpy (q, name, name_len);
+ q += name_len;
+ memcpy (q, FUNCDEF_SUFFIX, FUNCDEF_SUFFIX_LEN);
+ q += FUNCDEF_SUFFIX_LEN;
+ }
+ else
+ {
+ p = (char *)xmalloc (name_len + 1 + value_len + 1);
+ memcpy (p, name, name_len);
+ q = p + name_len;
+ }
+ q[0] = '=';
if (value && *value)
- strcpy (p + name_len + 1, value);
+ memcpy (q + 1, value, value_len + 1);
else
- p[name_len + 1] = '\0';
+ q[1] = '\0';
return (p);
}
@@ -3952,7 +3981,7 @@
/* Gee, I'd like to get away with not using savestring() if we're
using the cached exportstr... */
list[list_index] = USE_EXPORTSTR ? savestring (value)
- : mk_env_string (var->name, value);
+ : mk_env_string (var->name, value, function_p (var));
if (USE_EXPORTSTR == 0)
SAVE_EXPORTSTR (var, list[list_index]);
diff -ur ../bash-4.3orig/version.c ./version.c
--- ../bash-4.3orig/version.c 2013-03-10 13:20:13.000000000 -0400
+++ ./version.c 2014-09-27 17:43:08.716472328 -0400
@@ -83,7 +83,7 @@
show_shell_version (extended)
int extended;
{
- printf (_("GNU bash, version %s (%s)\n"), shell_version_string (), MACHTYPE);
+ printf (_("GNU bash, version %s (%s) SlowRiot build 2014-09-27\n"), shell_version_string (), MACHTYPE);
if (extended)
{
printf ("%s\n", _(bash_copyright));
diff -ur ../bash-4.3orig/y.tab.c ./y.tab.c
--- ../bash-4.3orig/y.tab.c 2014-09-27 17:52:38.880472141 -0400
+++ ./y.tab.c 2014-09-26 09:48:04.194597937 -0400
@@ -5265,6 +5265,8 @@
FREE (word_desc_to_read);
word_desc_to_read = (WORD_DESC *)NULL;
+ eol_ungetc_lookahead = 0;
+
current_token = '\n'; /* XXX */
last_read_token = '\n';
token_to_read = '\n';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment