Bash-4.3 Official Patch 23

2014-08-20 Thread Chet Ramey
 BASH PATCH REPORT
 =

Bash-Release:   4.3
Patch-ID:   bash43-023

Bug-Reported-by:Tim Friske 
Bug-Reference-ID:   

Bug-Reference-URL:  
http://lists.gnu.org/archive/html/bug-bash/2014-06/msg00056.html

Bug-Description:

Bash does not correctly parse process substitution constructs that contain
unbalanced parentheses as part of the contained command.

Patch (apply with `patch -p0'):

*** ../bash-4.3-patched/subst.h 2014-01-11 21:02:27.0 -0500
--- subst.h 2014-07-20 17:25:01.0 -0400
***
*** 83,87 
 Start extracting at (SINDEX) as if we had just seen "<(".
 Make (SINDEX) get the position just after the matching ")". */
! extern char *extract_process_subst __P((char *, char *, int *));
  #endif /* PROCESS_SUBSTITUTION */
  
--- 83,87 
 Start extracting at (SINDEX) as if we had just seen "<(".
 Make (SINDEX) get the position just after the matching ")". */
! extern char *extract_process_subst __P((char *, char *, int *, int));
  #endif /* PROCESS_SUBSTITUTION */
  
*** ../bash-4.3-patched/subst.c 2014-05-15 08:26:45.0 -0400
--- subst.c 2014-07-20 17:26:44.0 -0400
***
*** 1193,1202 
 Make (SINDEX) get the position of the matching ")". */ /*))*/
  char *
! extract_process_subst (string, starter, sindex)
   char *string;
   char *starter;
   int *sindex;
  {
return (extract_delimited_string (string, sindex, starter, "(", ")", 
SX_COMMAND));
  }
  #endif /* PROCESS_SUBSTITUTION */
--- 1193,1208 
 Make (SINDEX) get the position of the matching ")". */ /*))*/
  char *
! extract_process_subst (string, starter, sindex, xflags)
   char *string;
   char *starter;
   int *sindex;
+  int xflags;
  {
+ #if 0
return (extract_delimited_string (string, sindex, starter, "(", ")", 
SX_COMMAND));
+ #else
+   xflags |= (no_longjmp_on_fatal_error ? SX_NOLONGJMP : 0);
+   return (xparse_dolparen (string, string+*sindex, sindex, xflags));
+ #endif
  }
  #endif /* PROCESS_SUBSTITUTION */
***
*** 1786,1790 
  if (string[si] == '\0')
CQ_RETURN(si);
! temp = extract_process_subst (string, (c == '<') ? "<(" : ">(", &si);
  free (temp);  /* no SX_ALLOC here */
  i = si;
--- 1792,1796 
  if (string[si] == '\0')
CQ_RETURN(si);
! temp = extract_process_subst (string, (c == '<') ? "<(" : ">(", &si, 
0);
  free (temp);  /* no SX_ALLOC here */
  i = si;
***
*** 8250,8254 
  t_index = sindex + 1; /* skip past both '<' and LPAREN */
  
!   temp1 = extract_process_subst (string, (c == '<') ? "<(" : ">(", 
&t_index); /*))*/
sindex = t_index;
  
--- 8256,8260 
  t_index = sindex + 1; /* skip past both '<' and LPAREN */
  
!   temp1 = extract_process_subst (string, (c == '<') ? "<(" : ">(", 
&t_index, 0); /*))*/
sindex = t_index;
  
*** ../bash-4.3/patchlevel.h2012-12-29 10:47:57.0 -0500
--- patchlevel.h2014-03-20 20:01:28.0 -0400
***
*** 26,30 
 looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 22
  
  #endif /* _PATCHLEVEL_H_ */
--- 26,30 
 looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 23
  
  #endif /* _PATCHLEVEL_H_ */

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



Bash-4.3 Official Patch 24

2014-08-20 Thread Chet Ramey
 BASH PATCH REPORT
 =

Bash-Release:   4.3
Patch-ID:   bash43-024

Bug-Reported-by:Corentin Peuvrel 
Bug-Reference-ID:   <53ce9e5d.6050...@pom-monitoring.com>
Bug-Reference-URL:  
http://lists.gnu.org/archive/html/bug-bash/2014-07/msg00021.html

Bug-Description:

Indirect variable references do not work correctly if the reference
variable expands to an array reference using a subscript other than 0
(e.g., foo='bar[1]' ; echo ${!foo}).

Patch (apply with `patch -p0'):

*** ../bash-4.3-patched/subst.c 2014-06-03 09:32:44.0 -0400
--- subst.c 2014-07-23 09:58:19.0 -0400
***
*** 7375,7379 
  
if (want_indir)
! tdesc = parameter_brace_expand_indir (name + 1, var_is_special, quoted, 
quoted_dollar_atp, contains_dollar_at);
else
  tdesc = parameter_brace_expand_word (name, var_is_special, quoted, 
PF_IGNUNBOUND|(pflags&(PF_NOSPLIT2|PF_ASSIGNRHS)), &ind);
--- 7445,7455 
  
if (want_indir)
! {
!   tdesc = parameter_brace_expand_indir (name + 1, var_is_special, quoted, 
quoted_dollar_atp, contains_dollar_at);
!   /* Turn off the W_ARRAYIND flag because there is no way for this 
function
!to return the index we're supposed to be using. */
!   if (tdesc && tdesc->flags)
!   tdesc->flags &= ~W_ARRAYIND;
! }
else
  tdesc = parameter_brace_expand_word (name, var_is_special, quoted, 
PF_IGNUNBOUND|(pflags&(PF_NOSPLIT2|PF_ASSIGNRHS)), &ind);
*** ../bash-4.3/patchlevel.h2012-12-29 10:47:57.0 -0500
--- patchlevel.h2014-03-20 20:01:28.0 -0400
***
*** 26,30 
 looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 23
  
  #endif /* _PATCHLEVEL_H_ */
--- 26,30 
 looks for to find the patch level (for the sccs version string). */
  
! #define PATCHLEVEL 24
  
  #endif /* _PATCHLEVEL_H_ */

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



Substring Expansion does not work as intended

2014-08-20 Thread eckard . brauer
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: x86_64-pc-linux-gnu-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I. -I./include -I. -I./include -I./lib  
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
 -DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin' 
-DSYS_BASHRC='/etc/bash/bashrc' -DSYS_BASH_LOGOUT='/etc/bash/bash_logout' 
-DNON_INTERACTIVE_LOGIN_SHELLS -DSSH_SOURCE_BASHRC -march=core2 -O2 -pipe
uname output: Linux walter 3.15.8-geek #2 SMP PREEMPT Tue Aug 12 14:12:15 CEST 
2014 x86_64 Intel(R) Core(TM)2 Duo CPU T7500 @ 2.20GHz GenuineIntel GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.2
Patch Level: 47
Release Status: release

Description:
Substring Expansion actually works different than manpage states, 
namely:

"If offset evaluates to a number less than zero, the value is used as 
an offset from the end of the value of parameter."

Repeat-By:
x="abcdef"; echo "${x:-2}"
Expected: ef
Got:  abcdef

or:
x="abcdef"; echo "${x:-2:1}"
Expected: e
Got:  abcdef




Re: Substring Expansion does not work as intended

2014-08-20 Thread Eric Blake
On 08/20/2014 07:05 AM, eckard.bra...@gmx.de wrote:

Not a bug.

> 
> Description:
>   Substring Expansion actually works different than manpage states, 
> namely:
> 
>   "If offset evaluates to a number less than zero, the value is used as 
> an offset from the end of the value of parameter."

Read further.

"Note that a negative offset must be separated from the colon by at
least one space to avoid being confused with the :- expansion."

> 
> Repeat-By:
>   x="abcdef"; echo "${x:-2}"
>   Expected: ef
>   Got:  abcdef

echo "${x: -2}"

> 
>   or:
>   x="abcdef"; echo "${x:-2:1}"
>   Expected: e
>   Got:  abcdef

echo "${x: -2:1}"

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: Substring Expansion does not work as intended

2014-08-20 Thread Davide Brini
On Wed, 20 Aug 2014 15:05:48 +0200, eckard.bra...@gmx.de wrote:

> Description:
>   Substring Expansion actually works different than manpage states,
> namely:
> 
>   "If offset evaluates to a number less than zero, the value is
> used as an offset from the end of the value of parameter."
> 
> Repeat-By:
>   x="abcdef"; echo "${x:-2}"
>   Expected: ef
>   Got:  abcdef
> 
>   or:
>   x="abcdef"; echo "${x:-2:1}"
>   Expected: e
>   Got:  abcdef

One line below it also says: "Note that a negative offset must be separated
from the colon by at least one space to avoid being confused  with  the  :-
expansion."

$ x="abcdef"; echo "${x: -2}"
ef
$ x="abcdef"; echo "${x: -2:1}"
e

-- 
D.



Re: Substring Expansion does not work as intended

2014-08-20 Thread Greg Wooledge
On Wed, Aug 20, 2014 at 03:05:48PM +0200, eckard.bra...@gmx.de wrote:
>   "If offset evaluates to a number less than zero, the value is used as 
> an offset from the end of the value of parameter."
> 
> Repeat-By:
>   x="abcdef"; echo "${x:-2}"
>   Expected: ef
>   Got:  abcdef

This is a result of the collision of two different syntaxes.  Bash is
using the ${parameter:-word} ("Use Default Values") syntax here.

There are two ways to work around this:

${x: -2}
${x:(-2)}

Either one of these avoids the :- syntax ambiguity.  I prefer the
parentheses myself.



Re: Substring Expansion does not work as intended

2014-08-20 Thread Eckard Brauer
Hello,

I see.

My fault - thanks for the lesson... thought I had already used that at
a time, but can't remember for sure.

@Greg: The explanation does illustrate it very nice, as I regularly use
the ":-" - should have noticed that.

Thanks again, and kind regards
Eckard

Am Wed, 20 Aug 2014 07:50:09 -0600
schrieb Eric Blake :

> On 08/20/2014 07:05 AM, eckard.bra...@gmx.de wrote:
> 
> Not a bug.
> 
> > 
> > Description:
> > Substring Expansion actually works different than manpage
> > states, namely:
> > 
> > "If offset evaluates to a number less than zero, the value
> > is used as an offset from the end of the value of parameter."
> 
> Read further.
> 
> "Note that a negative offset must be separated from the colon by at
> least one space to avoid being confused with the :- expansion."
> 
> > 
> > Repeat-By:
> > x="abcdef"; echo "${x:-2}"
> > Expected: ef
> > Got:  abcdef
> 
> echo "${x: -2}"
> 
> > 
> > or:
> > x="abcdef"; echo "${x:-2:1}"
> > Expected: e
> > Got:  abcdef
> 
> echo "${x: -2:1}"
> 



-- 
:)


signature.asc
Description: PGP signature


Re: Substring Expansion does not work as intended

2014-08-20 Thread Chris F.A. Johnson

On Wed, 20 Aug 2014, Eric Blake wrote:


On 08/20/2014 07:05 AM, eckard.bra...@gmx.de wrote:

Not a bug.



Description:
Substring Expansion actually works different than manpage states, 
namely:

"If offset evaluates to a number less than zero, the value is used as an 
offset from the end of the value of parameter."


Read further.

"Note that a negative offset must be separated from the colon by at
least one space to avoid being confused with the :- expansion."


Repeat-By:
x="abcdef"; echo "${x:-2}"
Expected: ef
Got:  abcdef


echo "${x: -2}"


   Or use a variable:

o=-2
echo "${x:$o}"

--
Chris F.A. Johnson,