Re: Bash 5.2.0: Memory leak with $(

2024-01-19 Thread Chet Ramey

On 1/15/24 8:36 PM, pou...@tutanota.com wrote:




Would you please consider releasing these as an official patch?


I have the patch for the original report queued up for the next batch of
patches.

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



OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: Bash 5.2.0: Memory leak with $(

2024-01-15 Thread pourko--- via Bug reports for the GNU Bourne Again SHell



> On Mon, Jan 8, 2024, 12:26  wrote:
>
>> Do any of the other six patches in that report also apply to Bash 5.2?
>>
>
> Yes, all but the one for the `kv' builtin which did not exist yet. See
> attached.
>
>>
>>
Would you please consider releasing these as an official patch?




Re: Bash 5.2.0: Memory leak with $(

2024-01-11 Thread pourko--- via Bug reports for the GNU Bourne Again SHell
Jan 10, 2024, 15:58 by grishale...@gmail.com:

> On Mon, Jan 8, 2024, 12:26  <> pou...@tutanota.com> > wrote:
>
>> Do any of the other six patches in that report also apply to Bash 5.2?
>>
>
> Yes, all but the one for the `kv' builtin which did not exist yet. See 
> attached.
>
>>
>>
Nice!

Will this find its place in the official "bash-5.2-patches" folder?





Re: Bash 5.2.0: Memory leak with $(

2024-01-10 Thread Grisha Levit
On Mon, Jan 8, 2024, 12:26  wrote:

> Do any of the other six patches in that report also apply to Bash 5.2?
>

Yes, all but the one for the `kv' builtin which did not exist yet. See
attached.

>
From 711ab85262884f2b91f09eceb9aefd0e2426ce67 Mon Sep 17 00:00:00 2001
From: Grisha Levit 
Date: Sat, 3 Jun 2023 16:51:26 -0400
Subject: [PATCH] various leaks

Found mostly by normal usage running a no-bash-malloc build with clang's
LeakSanitizer enabled. So far seems to provide very accurate results.

* arrayfunc.c
- quote_compound_array_word: make sure to free VALUE
- bind_assoc_var_internal: if assigning to a dynamic variable, make sure
  to free the key (usually assoc_insert would do it)

* bashline.c
- bash_command_name_stat_hook: free original *NAME if we are going to
  change what it points to (what the callers seem to expect)

* builtins/evalstring.c
- parse_and_execute: make sure to dispose of the parsed command
  resulting from a failed function import attempt
- open_redir_file: if we did not get a pointer to pass back the expanded
  filename, make sure to free the name

* examples/loadables/stat.c
- loadstat: bind_assoc_variable does not free its VALUE argument so make
  sure to do it

* subst.c
- param_expand: free temp1 value for codepaths that don't do it
---
 arrayfunc.c   | 6 +-
 bashline.c| 1 +
 builtins/evalstring.c | 4 
 examples/loadables/stat.c | 1 +
 subst.c   | 2 ++
 5 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/arrayfunc.c b/arrayfunc.c
index 2c05d15b..8ba64084 100644
--- a/arrayfunc.c
+++ b/arrayfunc.c
@@ -208,7 +208,10 @@ bind_assoc_var_internal (entry, hash, key, value, flags)
   newval = make_array_variable_value (entry, 0, key, value, flags);
 
   if (entry->assign_func)
-(*entry->assign_func) (entry, newval, 0, key);
+{
+  (*entry->assign_func) (entry, newval, 0, key);
+  FREE (key);
+}
   else
 assoc_insert (hash, key, newval);
 
@@ -985,6 +988,7 @@ quote_compound_array_word (w, type)
   if (t != w+ind)
free (t);
   strcpy (nword + i, value);
+  free (value);
 
   return nword;
 }
diff --git a/bashline.c b/bashline.c
index c85b05b6..bd7548cc 100644
--- a/bashline.c
+++ b/bashline.c
@@ -1928,6 +1928,7 @@ bash_command_name_stat_hook (name)
   result = search_for_command (cname, 0);
   if (result)
 {
+  FREE (*name);
   *name = result;
   return 1;
 }
diff --git a/builtins/evalstring.c b/builtins/evalstring.c
index df3dd68e..20c6a4a7 100644
--- a/builtins/evalstring.c
+++ b/builtins/evalstring.c
@@ -461,6 +461,8 @@ parse_and_execute (string, from_file, flags)
 		  should_jump_to_top_level = 0;
 		  last_result = last_command_exit_value = EX_BADUSAGE;
 		  set_pipestatus_from_exit (last_command_exit_value);
+		  dispose_command(command);
+		  global_command = (COMMAND *)NULL;
 		  reset_parser ();
 		  break;
 		}
@@ -762,6 +764,8 @@ open_redir_file (r, fnp)
 
   if (fnp)
 *fnp = fn;
+  else
+free (fn);
   return fd;
 }
 
diff --git a/examples/loadables/stat.c b/examples/loadables/stat.c
index 1e60e7b6..ed5c9764 100644
--- a/examples/loadables/stat.c
+++ b/examples/loadables/stat.c
@@ -349,6 +349,7 @@ loadstat (vname, var, fname, flags, fmt, sp)
   key = savestring (arraysubs[i]);
   value = statval (i, fname, flags, fmt, sp);
   v = bind_assoc_variable (var, vname, key, value, ASS_FORCE);
+  free (value);
 }
   return 0;
 }
diff --git a/subst.c b/subst.c
index 1ac6eb2d..ff0602da 100644
--- a/subst.c
+++ b/subst.c
@@ -10727,6 +10727,7 @@ comsub:
 	{
 	  chk_atstar (temp, quoted, pflags, quoted_dollar_at_p, contains_dollar_at);
 	  tdesc = parameter_brace_expand_word (temp, SPECIAL_VAR (temp, 0), quoted, pflags, 0);
+	  free (temp1);
 	  if (tdesc == _wdesc_error || tdesc == _wdesc_fatal)
 		return (tdesc);
 	  ret = tdesc;
@@ -10739,6 +10740,7 @@ comsub:
 	{
 	  set_exit_status (EXECUTION_FAILURE);
 	  report_error (_("%s: invalid variable name for name reference"), temp);
+	  free (temp1);
 	  return (_wdesc_error);	/* XXX */
 	}
 	  else
-- 
2.43.0



Re: Bash 5.2.0: Memory leak with $(

2024-01-08 Thread pourko--- via Bug reports for the GNU Bourne Again SHell
Jan 8, 2024, 09:23 by chet.ra...@case.edu:

>
> *** ../bash-5.2-patched/builtins/evalstring.c Tue Dec 13 12:53:21 2022
> --- builtins/evalstring.c Tue Nov 28 17:25:39 2023
> ***
> *** 763,766 
> --- 773,779 
>  if (fnp)
>  *fnp = fn;
> +   else
> + free (fn);
> +
>  return fd;
>  }
>
>
That fixed the leak perfectly. Thank you!

Do any of the other six patches in that report also apply to Bash 5.2?





Re: Bash 5.2.0: Memory leak with $(

2024-01-08 Thread Chet Ramey
On 1/7/24 1:17 AM, pourko--- via Bug reports for the GNU Bourne Again SHell 
wrote:



  [2]:  > 
https://git.savannah.gnu.org/cgit/bash.git/diff/builtins/evalstring.c?h=devel=81f7b44564cd1510788035cea7c59631865a7db2=1#n766



Could we maybe get a patch for the 5.2 series?


*** ../bash-5.2-patched/builtins/evalstring.c   Tue Dec 13 12:53:21 2022
--- builtins/evalstring.c   Tue Nov 28 17:25:39 2023
***
*** 763,766 
--- 773,779 
if (fnp)
  *fnp = fn;
+   else
+ free (fn);
+
return fd;
  }



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



OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: Bash 5.2.0: Memory leak with $(

2024-01-08 Thread Chet Ramey

On 1/7/24 12:59 AM, Grisha Levit wrote:

On Sun, Jan 7, 2024, 00:26 pourko--- via Bug reports for the GNU Bourne
Again SHell  wrote:


For demonstration, put a $(

The bug is not present in bashes before 5.2.0.




I believe this is fixed in (yet unreleased) Bash 5.3. See report [1]
applied in [2].

  [1]:  https://lists.gnu.org/archive/html/bug-bash/2023-06/msg00045.html
  [2]:
https://git.savannah.gnu.org/cgit/bash.git/diff/builtins/evalstring.c?h=devel=81f7b44564cd1510788035cea7c59631865a7db2=1#n766


It's the change to open_redir_file that makes the difference, in case it's
not clear from the diff.

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



OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: Bash 5.2.0: Memory leak with $(

2024-01-07 Thread pourko--- via Bug reports for the GNU Bourne Again SHell
Jan 7, 2024, 00:00 by grishale...@gmail.com:

> I believe this is fixed in (yet unreleased) Bash 5.3. See report [1]
> applied in [2].
>
>  [1]:  https://lists.gnu.org/archive/html/bug-bash/2023-06/msg00045.html
>  [2]:
> https://git.savannah.gnu.org/cgit/bash.git/diff/builtins/evalstring.c?h=devel=81f7b44564cd1510788035cea7c59631865a7db2=1#n766
>
Can these patches be safely applied to Bash 5.2?





Re: Bash 5.2.0: Memory leak with $(

2024-01-06 Thread pourko--- via Bug reports for the GNU Bourne Again SHell
Jan 6, 2024, 23:59 by grishale...@gmail.com:

>
>
> On Sun, Jan 7, 2024, 00:26 pourko--- via Bug reports for the GNU Bourne Again 
> SHell <> bug-bash@gnu.org> > wrote:
>
>> For demonstration, put a $(> becomes very noticeable:
>>
>
>
>> The bug is not present in bashes before 5.2.0.
>>
>
> I believe this is fixed in (yet unreleased) Bash 5.3. See report [1] applied 
> in [2].
>
>  [1]:  > https://lists.gnu.org/archive/html/bug-bash/2023-06/msg00045.html
>  [2]:  > 
> https://git.savannah.gnu.org/cgit/bash.git/diff/builtins/evalstring.c?h=devel=81f7b44564cd1510788035cea7c59631865a7db2=1#n766
>

Could we maybe get a patch for the 5.2 series?

It's unclear when stable distros will start shipping with 5.3, and reverting to 
5.1 is not a pleasant alternative.





Re: Bash 5.2.0: Memory leak with $(

2024-01-06 Thread Grisha Levit
On Sun, Jan 7, 2024, 00:26 pourko--- via Bug reports for the GNU Bourne
Again SHell  wrote:

> For demonstration, put a $( becomes very noticeable:
>

The bug is not present in bashes before 5.2.0.
>

I believe this is fixed in (yet unreleased) Bash 5.3. See report [1]
applied in [2].

 [1]:  https://lists.gnu.org/archive/html/bug-bash/2023-06/msg00045.html
 [2]:
https://git.savannah.gnu.org/cgit/bash.git/diff/builtins/evalstring.c?h=devel=81f7b44564cd1510788035cea7c59631865a7db2=1#n766


Bash 5.2.0: Memory leak with $(

2024-01-06 Thread pourko--- via Bug reports for the GNU Bourne Again SHell
For demonstration, put a $(/tmp/file
while :;do
  var=$(