Memory Leak - Bash 4.3.x30

2024-03-26 Thread Jordi Ferrer
   Just in case for people running old servers:

   This simple code cause a memory leak in bash:

   #!/bin/bash
   #
   Array=("S" "E")
   while [ 1 ]; do
   A=${Array[0]}
   done

   But, adding colons to the assignment it doesn't:

   #!/bin/bash
   #
   Array=("S" "E")
   while [ 1 ]; do
   A="${Array[0]}"
   done

   Just reading the array content it doesn't:

   #!/bin/bash
   #
   Array=("S" "E")
   while [ 1 ]; do
   echo ${Array[0]}
   done

   So looks it like it's indexing the array and assigning it to another
   variable without "" causes a memory leak.

   # bash --version

   GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)
   Copyright (C) 2013 Free Software Foundation, Inc.
   License GPLv3+: GNU GPL version 3 or later
   [1]
   This is free software; you are free to change and redistribute it.
   There is NO WARRANTY, to the extent permitted by law.

   # ldd /bin/bash
   linux-vdso.so.1 (0x7ffcd2f27000)
   libncurses.so.5 => /lib/x86_64-linux-gnu/libncurses.so.5
   (0x7f26f4dbf000)
   libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5
   (0x7f26f4b95000)
   libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x7f26f4991000)
   libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x7f26f45e6000)
   /lib64/ld-linux-x86-64.so.2 (0x7f26f4fe4000)

   # dpkg -l |grep libncurses
   ii  libncurses5:amd64
   5.9+20140913-1+deb8u3amd64shared libraries for
   terminal handling
   ii  libncurses5-dev:amd64
   5.9+20140913-1+deb8u3amd64developer's libraries
   for ncurses
   ii  libncursesw5:amd64
   5.9+20140913-1+deb8u3amd64shared libraries for
   terminal handling (wide character support)

   # dpkg -l |grep libtinfo
   ii  libtinfo-dev:amd64
   5.9+20140913-1+deb8u3amd64developer's library
   for the low-level terminfo library
   ii  libtinfo5:amd64
   5.9+20140913-1+deb8u3amd64shared low-level
   terminfo library for terminal handling

   # cat /etc/debian_version
   8.11

   # uname -a

   Linux city 4.9.110-Mod #1 SMP Mon Oct 19 12:46:42 CEST 2020 x86_64
   GNU/Linux

--
Jordi Ferrer
INSTAL·LACIONS, TELECOMUNICACIONS I INFORMÀTICA
[2]jfer...@wattia.cat
(+34) 634 631 625

Wattia Innova S.L.  |  C/ Bòsnia, 6-8  |  17800 - Olot, Girona
Tel. (+34) 972 26 80 02  |  [3]http://wattia.cat

Avis Legal. La informació que conté aquest missatge de correu electrònic és CONF
IDENCIAL i pot incloure dades de caràcter reservat.
El seu accés o ús per part d'una tercera persona no autoritzada pot ser il·legal
. Si vostè no n'és el destinatari, si us plau elimini'l
i ens ho faci saber immediatament per aquesta mateixa via o pel telèfon (+34 972
 26 80 02). El correu electrònic no permet assegurar la
confidencialitat dels missatges, ni la seva recepció íntegra i correcta. No assu
mim cap responsabilitat per aquestes circumstàncies.
Si el destinatari no autoritza l'ús del correu electrònic o l'arxivament dels mi
ssatges, li preguem que ens ho comuniqui.

Abans d'imprimir aquest missatge pensi bé si és realment necessari fer-ho: El me
di ambient és cosa de tots!

References

   1. http://gnu.org/licenses/gpl.html
   2. mailto:jfer...@wattia.cat
   3. http://wattia.cat/


Debian bug #929178: wrong trap displayed inside functions

2024-03-26 Thread Oğuz
On Tuesday, March 26, 2024, Martin D Kealey  wrote:
>
> When forwarding incoming HTML to a text-only list, most mailing list
> servers will put the hyperlinks in a footnote, so that that long links
> won't obscure the text they apply to. (The better ones only do this when
> text text and its hyperlink differ; if the text and its hyperlink match
> (like when you have XX for any XX) then nothing is gained
> by duplicating it. That would appear to be the case with this mailing
> list.)
>
> Some mail receivers (e.g. Gmail) will convert bare text that looks like a
> hyperlink back into a hyperlink, which is how you get clickable links in
> the footnote.
>

They don't actually type those brackets then. Thanks


-- 
Oğuz


Re: Debian bug #929178: wrong trap displayed inside functions

2024-03-26 Thread Martin D Kealey
On Tue, 26 Mar 2024 at 04:05, Oğuz  wrote:

> On Mon, Mar 25, 2024 at 8:38 PM G. Branden Robinson
>  wrote:
> > [1]
> > [1] http...
>
> I keep seeing this. Why don't you guys just paste the link?
>

When forwarding incoming HTML to a text-only list, most mailing list
servers will put the hyperlinks in a footnote, so that that long links
won't obscure the text they apply to. (The better ones only do this when
text text and its hyperlink differ; if the text and its hyperlink match
(like when you have XX for any XX) then nothing is gained
by duplicating it. That would appear to be the case with this mailing list.)

Some mail receivers (e.g. Gmail) will convert bare text that looks like a
hyperlink back into a hyperlink, which is how you get clickable links in
the footnote.

-Martin


Re: feat: exit 1 "file not found"

2024-03-26 Thread Chet Ramey

On 3/22/24 3:29 PM, teknopaul wrote:

Hi not sure if this is the correct forum...

exit builtin accepts one and only one arg currently.

Would it be backwards compatible and generally useful to support echoing a 
reason for exiting?


Thanks for the suggestion. I don't see this as being of enough general use
to make part of `exit' when there are so many easy functions to provide it.

--
``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/




funsub in PS2

2024-03-26 Thread Grisha Levit
Having funsubs in PS2 seems to cause input tokens that are split across
lines to be partially replaced with the last token of the last funsub
to be parsed while expanding the prompt string.

$ PS2='${ : ; }> '
$ printf '[%s]\n' ab\
> cd
[XXcd]



[PATCH] fix cmd and hist nums in ${var@P} inside $PS[012]

2024-03-26 Thread Grisha Levit
When \# or \! is decoded in a ${var@P} expansion embedded in a prompt
string, the value can be off by one from that of the same sequence
embedded directly in the prompt string.

$ H='\!'
$ PS1='(\!:${H@P}) $'
(3:2 501:500) $

* parse.y
- decode_prompt_string: accept new int flag to signify a real prompt
  string is being decoded; update callers
* externs.h
- decode_prompt_string: update declaration
---
 eval.c  |  2 +-
 externs.h   |  2 +-
 parse.y | 23 ---
 print_cmd.c |  2 +-
 subst.c |  2 +-
 5 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/eval.c b/eval.c
index a08cb578..2fee976c 100644
--- a/eval.c
+++ b/eval.c
@@ -157,7 +157,7 @@ reader_loop (void)
 
  old_eof = EOF_Reached;
  EOF_Reached = 0;
- ps0_string = decode_prompt_string (ps0_prompt);
+ ps0_string = decode_prompt_string (ps0_prompt, 1);
  if (ps0_string && *ps0_string)
{
  fprintf (stderr, "%s", ps0_string);
diff --git a/externs.h b/externs.h
index b60fb79e..683c72f6 100644
--- a/externs.h
+++ b/externs.h
@@ -128,7 +128,7 @@ extern void clear_shell_input_line (void);
 
 extern int handle_ignoreeof (int);
 
-extern char *decode_prompt_string (char *);
+extern char *decode_prompt_string (char *, int);
 
 extern int get_current_prompt_level (void);
 extern void set_current_prompt_level (int);
diff --git a/parse.y b/parse.y
index 3e28d24d..3211ea64 100644
--- a/parse.y
+++ b/parse.y
@@ -6036,7 +6036,7 @@ prompt_again (int force)
 prompt_string_pointer = _prompt;
 
   temp_prompt = *prompt_string_pointer
-   ? decode_prompt_string (*prompt_string_pointer)
+   ? decode_prompt_string (*prompt_string_pointer, 1)
: (char *)NULL;
 
   if (temp_prompt == 0)
@@ -6139,10 +6139,10 @@ prompt_history_number (char *pmt)
 */
 #define PROMPT_GROWTH 48
 char *
-decode_prompt_string (char *string)
+decode_prompt_string (char *string, int is_prompt)
 {
   WORD_LIST *list;
-  char *result, *t, *orig_string, *last_lastarg;
+  char *result, *t, *last_lastarg;
   struct dstack save_dstack;
   int last_exit_value, last_comsub_pid, last_comsub_status;
 #if defined (PROMPT_STRING_DECODE)
@@ -6155,11 +6155,16 @@ decode_prompt_string (char *string)
   char timebuf[128];
   char *timefmt;
   size_t tslen;
+  static char *decoding_prompt;
 
   result = (char *)xmalloc (result_size = PROMPT_GROWTH);
   result[result_index = 0] = 0;
   temp = (char *)NULL;
-  orig_string = string;
+
+  /* Keep track of which (real) prompt string is being decoded so that we can
+ process embedded ${var@P} expansions correctly. */
+  if (is_prompt)
+decoding_prompt = string;
 
   while (c = *string++)
 {
@@ -6175,7 +6180,7 @@ decode_prompt_string (char *string)
 #if !defined (HISTORY)
temp = savestring ("1");
 #else /* HISTORY */
-   temp = itos (prompt_history_number (orig_string));
+   temp = itos (prompt_history_number (decoding_prompt));
 #endif /* HISTORY */
string--;   /* add_string increments string again. */
goto add_string;
@@ -6436,7 +6441,7 @@ decode_prompt_string (char *string)
  n = current_command_number;
  /* If we have already incremented current_command_number (PS4,
 ${var@P}), compensate */
- if (orig_string != ps0_prompt && orig_string != ps1_prompt && 
orig_string != ps2_prompt)
+ if (decoding_prompt != ps0_prompt && decoding_prompt != 
ps1_prompt && decoding_prompt != ps2_prompt)
n--;
  temp = itos (n);
  goto add_string;
@@ -6445,7 +6450,7 @@ decode_prompt_string (char *string)
 #if !defined (HISTORY)
  temp = savestring ("1");
 #else /* HISTORY */
- temp = itos (prompt_history_number (orig_string));
+ temp = itos (prompt_history_number (decoding_prompt));
 #endif /* HISTORY */
  goto add_string;
 
@@ -6570,6 +6575,10 @@ not_escape:
 }
 
   dstack = save_dstack;
+#if defined (PROMPT_STRING_DECODE)
+  if (is_prompt)
+decoding_prompt = (char *)NULL;
+#endif
 
   return (result);
 }
diff --git a/print_cmd.c b/print_cmd.c
index 9d3ab73b..36268e19 100644
--- a/print_cmd.c
+++ b/print_cmd.c
@@ -460,7 +460,7 @@ indirection_level_string (void)
 return (indirection_string);
 
   old = change_flag ('x', FLAG_OFF);
-  ps4 = decode_prompt_string (ps4);
+  ps4 = decode_prompt_string (ps4, 1);
   if (old)
 change_flag ('x', FLAG_ON);
 
diff --git a/subst.c b/subst.c
index 2c51021b..ee0afd67 100644
--- a/subst.c
+++ b/subst.c
@@ -8745,7 +8745,7 @@ string_transform (int xc, SHELL_VAR *v, char *s)
ret = ansicstr (s, strlen (s), 0, 0, 0);
break;
   case 'P':
-   ret = decode_prompt_string (s);
+   ret = decode_prompt_string (s, 0);
break;
   case 'Q':