summaryrefslogtreecommitdiffstats
path: root/scratch/variables-affix-3.1.patch.2
blob: 9ee9d6b3b6c03b3a055bb8774cd5a7e2e27f5b02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
diff -rupN bash-3.1-postpatch/variables.c bash-3.1/variables.c
--- bash-3.1-postpatch/variables.c	2014-09-29 15:12:10.915662508 -0600
+++ bash-3.1/variables.c	2014-09-29 15:17:39.499385442 -0600
@@ -308,28 +308,38 @@ initialize_shell_variables (env, privmod
 
       /* If exported function, define it now.  Don't import functions from
 	 the environment in privileged mode. */
-      if (privmode == 0 && read_but_dont_execute == 0 && STREQN ("() {", string, 4))
-	{
-	  string_length = strlen (string);
-	  temp_string = (char *)xmalloc (3 + string_length + char_index);
+    if (privmode == 0 && read_but_dont_execute == 0
+        && STREQN (FUNCDEF_PREFIX, name, FUNCDEF_PREFIX_LEN)
+        && STREQ (name + char_index - FUNCDEF_SUFFIX_LEN, FUNCDEF_SUFFIX)
+        && STREQN ("() {", string, 4))
+    {
+      size_t name_length
+        = char_index - (FUNCDEF_PREFIX_LEN + FUNCDEF_SUFFIX_LEN); 
+      char *temp_name = name + FUNCDEF_PREFIX_LEN;
+      /* Temporarily remove the suffix. */ 
+      temp_name[name_length] = '\0'; 
 
-	  strcpy (temp_string, name);
-	  temp_string[char_index] = ' ';
-	  strcpy (temp_string + char_index + 1, string);
+      string_length = strlen (string);
+      temp_string = (char *)xmalloc (name_length + 1 + string_length + 1);
+      memcpy (temp_string, temp_name, name_length);
+      temp_string[name_length] = ' ';
+      memcpy (temp_string + name_length + 1, string, string_length + 1);
 
     /* Don't import function names that are invalid identifiers from the
        environment. */
-    if (legal_identifier (name))
-      parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
+      if (legal_identifier (temp_name))
+        parse_and_execute (temp_string, temp_name,
+            SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
 
-    if (temp_var = find_function (name))
+      if (temp_var = find_function (temp_name))
 	    {
 	      VSETATTR (temp_var, (att_exported|att_imported));
 	      array_needs_making = 1;
 	    }
 	  else
 	    report_error (_("error importing function definition for `%s'"), name);
-
+      /* Restore the original suffix. */
+      temp_name[name_length] = FUNCDEF_SUFFIX[0];
 	}
 #if defined (ARRAY_VARS)
 #  if 0