Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bash decode prompt string broken for 'W'

13 views
Skip to first unread message

Marty Pauley

unread,
Apr 3, 2011, 12:44:26 PM4/3/11
to bug-...@gnu.org, ba...@packages.debian.org
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: 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/shar
uname output: Linux gohan 2.6.37-2-amd64 #1 SMP Sun Feb 27 10:12:22
UTC 2011 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.1
Patch Level: 5
Release Status: release

Description:
The "\W" escape in the prompt is expanded incorrectly for some
directories. The problem is caused by the use of strcpy with
overlapping strings; but strcpy has undefined behaviour when the
strings overlap.

Repeat-By:
Set PS1 to include the "\W" escape, then cd to /home or /media to see
the problem: "home" is displayed as "hmee" and "media" is displayed as
"meiia". A transcript from my bash session is below:

bash-4.1$ PS1='\W$ '
~$ cd /home
hmee$ cd /media
meiia$ cd /etc
etc$ cd
~$ exit


Fix:
The patch below fixes the problem.

--- y.tab.c.orig 2011-04-04 01:12:23.000000000 +0900
+++ y.tab.c 2011-04-04 01:19:48.000000000 +0900
@@ -7481,7 +7481,8 @@
{
t = strrchr (t_string, '/');
if (t)
- strcpy (t_string, t + 1);
+ for ( temp = t_string; *t; temp++ )
+ *temp = *++t;
}
}
#undef ROOT_PATH

Chet Ramey

unread,
Apr 4, 2011, 8:15:47 AM4/4/11
to ma...@martian.org, bug-...@gnu.org, ba...@packages.debian.org, ch...@po.cwru.edu
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: 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/shar
> uname output: Linux gohan 2.6.37-2-amd64 #1 SMP Sun Feb 27 10:12:22
> UTC 2011 x86_64 GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
>
> Bash Version: 4.1
> Patch Level: 5
> Release Status: release
>
> Description:
> The "\W" escape in the prompt is expanded incorrectly for some
> directories. The problem is caused by the use of strcpy with
> overlapping strings; but strcpy has undefined behaviour when the
> strings overlap.

Upgrade. This is fixed by bash-4.1 patch 10.

Chet

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

0 new messages