bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bash-4.0 Official Patch 41


From: Chet Ramey
Subject: Bash-4.0 Official Patch 41
Date: Sat, 27 Sep 2014 22:52:14 -0400

                             BASH PATCH REPORT
                             =================

Bash-Release: 4.0
Patch-ID: bash40-041

Bug-Reported-by:        Florian Weimer <fweimer@redhat.com>
Bug-Reference-ID:
Bug-Reference-URL:

Bug-Description:

This patch changes the encoding bash uses for exported functions to avoid
clashes with shell variables and to avoid depending only on an environment
variable's contents to determine whether or not to interpret it as a shell
function.

Patch:

*** ../bash-4.0.40/variables.c  2014-09-16 19:20:48.000000000 -0400
--- variables.c 2014-09-27 21:01:42.000000000 -0400
***************
*** 78,81 ****
--- 78,86 ----
  #define ifsname(s)    ((s)[0] == 'I' && (s)[1] == 'F' && (s)[2] == 'S' && 
(s)[3] == '\0')
  
+ #define BASHFUNC_PREFIX               "BASH_FUNC_"
+ #define BASHFUNC_PREFLEN      10      /* == strlen(BASHFUNC_PREFIX */
+ #define BASHFUNC_SUFFIX               "%%"
+ #define BASHFUNC_SUFFLEN      2       /* == strlen(BASHFUNC_SUFFIX) */
+ 
  extern char **environ;
  
***************
*** 265,269 ****
  static void dispose_temporary_env __P((sh_free_func_t *));     
  
! static inline char *mk_env_string __P((const char *, const char *));
  static char **make_env_array_from_var_list __P((SHELL_VAR **));
  static char **make_var_export_array __P((VAR_CONTEXT *));
--- 270,274 ----
  static void dispose_temporary_env __P((sh_free_func_t *));     
  
! 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 *));
***************
*** 335,353 ****
        /* 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);
  
!         strcpy (temp_string, name);
!         temp_string[char_index] = ' ';
!         strcpy (temp_string + char_index + 1, string);
  
          /* 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 (temp_var = find_function (name))
            {
              VSETATTR (temp_var, (att_exported|att_imported));
--- 340,369 ----
        /* 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 (BASHFUNC_PREFIX, name, BASHFUNC_PREFLEN) &&
!         STREQ (BASHFUNC_SUFFIX, name + char_index - BASHFUNC_SUFFLEN) &&
!         STREQN ("() {", string, 4))
        {
+         size_t namelen;
+         char *tname;          /* desired imported function name */
+ 
+         namelen = char_index - BASHFUNC_PREFLEN - BASHFUNC_SUFFLEN;
+ 
+         tname = name + BASHFUNC_PREFLEN;      /* start of func name */
+         tname[namelen] = '\0';                /* now tname == func name */
+ 
          string_length = strlen (string);
!         temp_string = (char *)xmalloc (namelen + string_length + 2);
  
!         memcpy (temp_string, tname, namelen);
!         temp_string[namelen] = ' ';
!         memcpy (temp_string + namelen + 1, string, string_length + 1);
  
          /* Don't import function names that are invalid identifiers from the
             environment. */
!         if (absolute_program (tname) == 0 && (posixly_correct == 0 || 
legal_identifier (tname)))
!           parse_and_execute (temp_string, tname, 
SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);
  
!         if (temp_var = find_function (tname))
            {
              VSETATTR (temp_var, (att_exported|att_imported));
***************
*** 355,359 ****
            }
          else
!           report_error (_("error importing function definition for `%s'"), 
name);
        }
  #if defined (ARRAY_VARS)
--- 371,378 ----
            }
          else
!           report_error (_("error importing function definition for `%s'"), 
tname);
! 
!         /* Restore original suffix */
!         tname[namelen] = BASHFUNC_SUFFIX[0];
        }
  #if defined (ARRAY_VARS)
***************
*** 2506,2510 ****
  
    INVALIDATE_EXPORTSTR (var);
!   var->exportstr = mk_env_string (name, value);
  
    array_needs_making = 1;
--- 2525,2529 ----
  
    INVALIDATE_EXPORTSTR (var);
!   var->exportstr = mk_env_string (name, value, 0);
  
    array_needs_making = 1;
***************
*** 3325,3343 ****
  
  static inline char *
! mk_env_string (name, value)
       const char *name, *value;
  {
!   int name_len, value_len;
!   char        *p;
  
    name_len = strlen (name);
    value_len = STRLEN (value);
!   p = (char *)xmalloc (2 + name_len + value_len);
!   strcpy (p, name);
!   p[name_len] = '=';
    if (value && *value)
!     strcpy (p + name_len + 1, value);
    else
!     p[name_len + 1] = '\0';
    return (p);
  }
--- 3344,3383 ----
  
  static inline char *
! mk_env_string (name, value, isfunc)
       const char *name, *value;
+      int isfunc;
  {
!   size_t name_len, value_len;
!   char        *p, *q;
  
    name_len = strlen (name);
    value_len = STRLEN (value);
! 
!   /* If we are exporting a shell function, construct the encoded function
!      name. */
!   if (isfunc && value)
!     {
!       p = (char *)xmalloc (BASHFUNC_PREFLEN + name_len + BASHFUNC_SUFFLEN + 
value_len + 2);
!       q = p;
!       memcpy (q, BASHFUNC_PREFIX, BASHFUNC_PREFLEN);
!       q += BASHFUNC_PREFLEN;
!       memcpy (q, name, name_len);
!       q += name_len;
!       memcpy (q, BASHFUNC_SUFFIX, BASHFUNC_SUFFLEN);
!       q += BASHFUNC_SUFFLEN;
!     }
!   else
!     {
!       p = (char *)xmalloc (2 + name_len + value_len);
!       memcpy (p, name, name_len);
!       q = p + name_len;
!     }
! 
!   q[0] = '=';
    if (value && *value)
!     memcpy (q + 1, value, value_len + 1);
    else
!     q[1] = '\0';
! 
    return (p);
  }
***************
*** 3420,3424 ****
             using the cached exportstr... */
          list[list_index] = USE_EXPORTSTR ? savestring (value)
!                                          : mk_env_string (var->name, value);
  
          if (USE_EXPORTSTR == 0)
--- 3460,3464 ----
             using the cached exportstr... */
          list[list_index] = USE_EXPORTSTR ? savestring (value)
!                                          : mk_env_string (var->name, value, 
function_p (var));
  
          if (USE_EXPORTSTR == 0)
*** ../bash-4.0/patchlevel.h    2009-01-04 14:32:40.000000000 -0500
--- patchlevel.h        2009-02-22 16:11:31.000000000 -0500
***************
*** 26,30 ****
     looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 40
  
  #endif /* _PATCHLEVEL_H_ */
--- 26,30 ----
     looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 41
  
  #endif /* _PATCHLEVEL_H_ */

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]