bug-bash
[Top][All Lists]
Advanced

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

Bug in FUNCNAME array handling


From: Dr. Werner Fink
Subject: Bug in FUNCNAME array handling
Date: Mon, 13 Dec 2004 14:41:08 +0100
User-agent: Mutt/1.5.6i

Hi,

      the following few lines will cause a segmentation
fault of the bash 3.0 :

    unset POSIXLY_CORRECT
    function crash {
        unset FUNCNAME
        LANG=en_US.UTF-8
    }
    crash

this because the array variable FUNCNAME which is unset
during executing the shell function body will be updated
afterwards.  The attached patch add a check if the
variable is valid after the shell function body or after
a  file evaluation to avoid this.

         Werner

--- array.h
+++ array.h     2004-11-25 15:45:56.303010013 +0000
@@ -99,6 +99,11 @@
   do { array_rshift ((a), 1, (v)); } while (0)
 #define array_pop(a) \
   do { array_dispose_element (array_shift ((a), 1, 0)); } while (0)
+#define array_pop_save(a,n) \
+  do { \
+    if (find_variable(n) == NULL) break; \
+    array_dispose_element (array_shift ((a), 1, 0)); \
+  } while (0)
 
 #define GET_ARRAY_FROM_VAR(n, v, a) \
   do { \
--- execute_cmd.c
+++ execute_cmd.c       2004-11-25 15:48:00.459818125 +0000
@@ -3268,11 +3268,11 @@
 
   funcnest--;
 #if defined (ARRAY_VARS)
-  array_pop (bash_source_a);
-  array_pop (funcname_a);
-  array_pop (bash_lineno_a);
+  array_pop_save (bash_source_a, "BASH_SOURCE");
+  array_pop_save (funcname_a, "FUNCNAME");
+  array_pop_save (bash_lineno_a, "BASH_LINENO");
 #endif
-  
+
   if (variable_context == 0 || this_shell_function == 0)
     make_funcname_visible (0);
 
--- builtins/evalfile.c
+++ builtins/evalfile.c 2004-11-25 15:51:36.711389204 +0000
@@ -246,9 +246,9 @@
     }
 
 #if defined (ARRAY_VARS)
-  array_pop (bash_source_a);
-  array_pop (bash_lineno_a);
-  array_pop (funcname_a);
+  array_pop_save (bash_source_a, "BASH_SOURCE");
+  array_pop_save (bash_lineno_a, "BASH_LINENO");
+  array_pop_save (funcname_a, "FUNCNAME");
 #  if defined (DEBUGGER)
   if ((flags & FEVAL_NOPUSHARGS) == 0)
     {




reply via email to

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