Bug report command "cd"

2013-07-03 Thread Stephan van Ingen
Hello,

I hope this is the correct way to report a bug (as explained
here
).

*The version number of Bash*: 4.2.45(1)-release (x86_64-pc-linux-gnu)
*The hardware and operating system*. Laptop System76 Intel® Core™ i7-3610QM
CPU @ 2.30GHz × 8 with Ubuntu 13.04 (Raring Ringtale)
*The compiler used to compile Bash*. *dunno* :/ but maybe enough
information by dependies shown in attached dpkg-pbash.txt
*A description of the bug behaviour*.
I can not change directory to a directory starting with two dashes

*A short script or ‘recipe’ which exercises the bug and may be used to
reproduce it*:
*See this command line log:*
stephanbosal@in-laptop3:~/Downloads/Win8$ uname -a
Linux in-laptop3 *3.8.0-23-generic* *#34-Ubuntu* SMP Wed May 29 20:22:58
UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
stephanbosal@in-laptop3:~/Downloads/Win8$ *echo $SHELL*
/bin/bash
stephanbosal@in-laptop3:~/Downloads/Win8$ *bash --version*
GNU bash, version 4.2.45(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
stephanbosal@in-laptop3:~/Downloads/Win8$ *ls -l*
total 15130844
-rw-r--r-- 1 stephanbosal stephanbosal 7746568704 jul  2 09:22 smsboot.bin
-rw-r--r-- 1 stephanbosal stephanbosal 7747397632 jul  3 09:02
smsboot_mbr.bin
drwxrwxr-x 3 stephanbosal stephanbosal   4096 jul  3 11:31 *
--SMSBOOT-sources-*
stephanbosal@in-laptop3:~/Downloads/Win8$ *cd --SMSBOOT-sources-/*
bash: cd: --: invalid option
cd: usage: cd [-L|[-P [-e]]] [dir]
stephanbosal@in-laptop3:~/Downloads/Win8$ *cd \-\-SMSBOOT-sources-/*
bash: cd: --: invalid option
cd: usage: cd [-L|[-P [-e]]] [dir]
stephanbosal@in-laptop3:~/Downloads/Win8$ *cd \\-\\-SMSBOOT-sources-/*
bash: cd: \-\-SMSBOOT-sources-/: No such file or directory
stephanbosal@in-laptop3:~/Downloads/Win8$


Best regards!
Stephan,

--
Stephan van Ingen
http://stephanvaningen.net
--
Me transmitte sursum, Caledoni!
stephanbosal@in-laptop3:/bin$ dpkg -p bash
Package: bash
Essential: yes
Priority: required
Section: shells
Installed-Size: 1416
Maintainer: Ubuntu Developers 
Architecture: amd64
Multi-Arch: foreign
Version: 4.2-5ubuntu3
Replaces: bash-completion (<< 20060301-0), bash-doc (<= 2.05-1)
Depends: base-files (>= 2.1.12), debianutils (>= 2.15)
Pre-Depends: dash (>= 0.5.5.1-2.2), libc6 (>= 2.15), libtinfo5
Recommends: bash-completion (>= 20060301-0)
Suggests: bash-doc
Conflicts: bash-completion (<< 20060301-0)
Filename: pool/main/b/bash/bash_4.2-2ubuntu2_amd64.deb
Size: 642968
MD5sum: 273afd82a606d827be347bfa26900be9
Description: GNU Bourne Again SHell
 Bash is an sh-compatible command language interpreter that executes
 commands read from the standard input or from a file.  Bash also
 incorporates useful features from the Korn and C shells (ksh and csh).
 .
 Bash is ultimately intended to be a conformant implementation of the
 IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2).
 .
 The Programmable Completion Code, by Ian Macdonald, is now found in
 the bash-completion package.
Homepage: http://tiswww.case.edu/php/chet/bash/bashtop.html
Original-Maintainer: Matthias Klose 
stephanbosal@in-laptop3:/bin$ 



Re: Bug report command "cd"

2013-07-03 Thread Eric Blake
On 07/03/2013 03:52 AM, Stephan van Ingen wrote:
> Hello,
> 
> I hope this is the correct way to report a bug (as explained
> here

Yes. However, what you are reporting is not a bug, but a usage issue on
your part.

> stephanbosal@in-laptop3:~/Downloads/Win8$ *cd --SMSBOOT-sources-/*
> bash: cd: --: invalid option

You need to use one of these two constructs, to explicitly tell cd that
your directory name starts with '-' rather than being an option that cd
tries to interpret:

cd -- --SMSBOOT-sources-/*
cd ./--SMSBOOT-sources-/*

This is true for most unix-y commands, not just cd.

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



signature.asc
Description: OpenPGP digital signature


Re: Bug report command "cd"

2013-07-03 Thread Pierre Gaston
On Wed, Jul 3, 2013 at 12:52 PM, Stephan van Ingen
 wrote:
> Hello,
>
> I hope this is the correct way to report a bug (as explained
> here
> ).
>
> *The version number of Bash*: 4.2.45(1)-release (x86_64-pc-linux-gnu)
> *The hardware and operating system*. Laptop System76 Intel® Core™ i7-3610QM
> CPU @ 2.30GHz × 8 with Ubuntu 13.04 (Raring Ringtale)
> *The compiler used to compile Bash*. *dunno* :/ but maybe enough
> information by dependies shown in attached dpkg-pbash.txt
> *A description of the bug behaviour*.
> I can not change directory to a directory starting with two dashes
>
> *A short script or ‘recipe’ which exercises the bug and may be used to
> reproduce it*:
> *See this command line log:*
> stephanbosal@in-laptop3:~/Downloads/Win8$ uname -a
> Linux in-laptop3 *3.8.0-23-generic* *#34-Ubuntu* SMP Wed May 29 20:22:58
> UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
> stephanbosal@in-laptop3:~/Downloads/Win8$ *echo $SHELL*
> /bin/bash
> stephanbosal@in-laptop3:~/Downloads/Win8$ *bash --version*
> GNU bash, version 4.2.45(1)-release (x86_64-pc-linux-gnu)
> Copyright (C) 2011 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later >
> stephanbosal@in-laptop3:~/Downloads/Win8$ *ls -l*
> total 15130844
> -rw-r--r-- 1 stephanbosal stephanbosal 7746568704 jul  2 09:22 smsboot.bin
> -rw-r--r-- 1 stephanbosal stephanbosal 7747397632 jul  3 09:02
> smsboot_mbr.bin
> drwxrwxr-x 3 stephanbosal stephanbosal   4096 jul  3 11:31 *
> --SMSBOOT-sources-*
> stephanbosal@in-laptop3:~/Downloads/Win8$ *cd --SMSBOOT-sources-/*
> bash: cd: --: invalid option
> cd: usage: cd [-L|[-P [-e]]] [dir]
> stephanbosal@in-laptop3:~/Downloads/Win8$ *cd \-\-SMSBOOT-sources-/*
> bash: cd: --: invalid option
> cd: usage: cd [-L|[-P [-e]]] [dir]
> stephanbosal@in-laptop3:~/Downloads/Win8$ *cd \\-\\-SMSBOOT-sources-/*
> bash: cd: \-\-SMSBOOT-sources-/: No such file or directory
> stephanbosal@in-laptop3:~/Downloads/Win8$
>
>
> Best regards!
> Stephan,
>
> --
> Stephan van Ingen
> http://stephanvaningen.net
> --
> Me transmitte sursum, Caledoni!

This is a classic problem, quoting doesn't help because the quotes are
removed by the shell before calling the command.
cd \-dir is the same thing as cd -dir.

On the other hand if you do cd \\-dir it tries to find '\-dir' which
doesn't exist.

The 2 workarounds are:
cd -- -dir # -- tells cd that there are no more -options
cd ./-dir #  add a dirname that doesn't start with -



Re: Bug report command "cd"

2013-07-03 Thread Chris Down
Greetings.

On 3 July 2013 17:52, Stephan van Ingen  wrote:
> stephanbosal@in-laptop3:~/Downloads/Win8$ *cd --SMSBOOT-sources-/*
> bash: cd: --: invalid option
> cd: usage: cd [-L|[-P [-e]]] [dir]
> stephanbosal@in-laptop3:~/Downloads/Win8$ *cd \-\-SMSBOOT-sources-/*
> bash: cd: --: invalid option

This is not a bug, this is the way that POSIX option parsing works.
Backslashes are not the way to solve it, because it's not that `-` is
being interpreted as a special character, it's about the way that the
option parser works. See

The correct way is to do this:

cd -- --SMSBOOT-sources

Or:

cd ./--SMSBOOT-sources

Best,

Chris



Re: Bug report command "cd"

2013-07-03 Thread Chris Down
On 4 July 2013 00:08, Chris Down  wrote:
> Greetings.
>
> On 3 July 2013 17:52, Stephan van Ingen  wrote:
>> stephanbosal@in-laptop3:~/Downloads/Win8$ *cd --SMSBOOT-sources-/*
>> bash: cd: --: invalid option
>> cd: usage: cd [-L|[-P [-e]]] [dir]
>> stephanbosal@in-laptop3:~/Downloads/Win8$ *cd \-\-SMSBOOT-sources-/*
>> bash: cd: --: invalid option
>
> This is not a bug, this is the way that POSIX option parsing works.
> Backslashes are not the way to solve it, because it's not that `-` is
> being interpreted as a special character, it's about the way that the
> option parser works. See
>
> The correct way is to do this:
>
> cd -- --SMSBOOT-sources
>
> Or:
>
> cd ./--SMSBOOT-sources

Bah, missed the link.

http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.html



strcpy of overlapping memory ranges in prompt expansion

2013-07-03 Thread simon
Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: darwin13.0.0
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='darwin13.0.0' -DCONF_MACHTYPE='i386-apple-darwin13.0.0' 
-DCONF_VENDOR='apple' -DLOCALEDIR='/usr/local/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H -DMACOSX   -I.  -I. -I./include -I./lib -I./lib/intl 
-I/Users/simon/src/bash-4.2/lib/intl  -g -O2
uname output: Darwin darnassus 13.0.0 Darwin Kernel Version 13.0.0: Wed Jun 19 
17:59:46 PDT 2013; root:xnu-2422.1.26.0.1~2/RELEASE_X86_64 x86_64
Machine Type: i386-apple-darwin13.0.0

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

Description:
When using \w in the prompt and changing the directory outside of HOME
bash crashes with an abort trap.
strcpy(3) say src and dst must not overlap. OS X 10.9 checks that on
runtime and forcefully aborts your code if they do.

Repeat-By:
PS1="\w"
cd /
bash exists with an abort trap.

Fix:
Assign the return value from polite_directory_format to a temporary value.
If the pointers are different and only then do a strcpy
--- parse.y.orig2013-07-03 22:00:42.0 +0200
+++ parse.y 2013-07-03 22:02:23.0 +0200
@@ -5262,7 +5262,12 @@
else
  /* polite_directory_format is guaranteed to return a string
 no longer than PATH_MAX - 1 characters. */
- strcpy (t_string, polite_directory_format (t_string));
+  /* polite_directory_format might simply return the pointer 
to t_string
+ strcpy(3) tells dst and src may not overlap, OS X 10.9 
asserts this and
+ triggers an abort trap if that's the case */
+  temp = polite_directory_format (t_string);
+  if (temp != t_string)
+   strcpy (t_string, temp);
 
temp = trim_pathname (t_string, PATH_MAX - 1);
/* If we're going to be expanding the prompt string later,