Re: Infinite loop in bash glob matching

2017-05-18 Thread Greg Wooledge
On Thu, May 18, 2017 at 08:29:13AM +0200, Zoltán Herczeg wrote:
> I think throwing an error would be better than an undefined behaviour. Bash 
> throws error for solo parenthesis, a similar technique could be used here.

That's not really an option, because an unmatched [ isn't a syntax
error.  It's just a string.

imadev:~$ echo [
[

Generating an error for this would break backward compatibility.



Re: Infinite loop in bash glob matching

2017-05-18 Thread Chet Ramey
On 5/18/17 2:29 AM, Zoltán Herczeg wrote:
>> I read this as saying that it's a requirement on the application to ensure
>> that character classes are correctly formed, and it's unspecified behavior
>> if they're not.
>>
>> So you're right: people should not count on shells treating improperly-
>> formed character classes as literal characters.
> 
> Thank you for the explanation.
> 
> I think throwing an error would be better than an undefined behaviour. Bash 
> throws error for solo parenthesis, a similar technique could be used here.

That's not a good example, since a parenthesis is a shell metacharacter,
and an unquoted paren in a place where it's not syntactially valid is a
syntax error.  The choice here is between not matching because the pattern
is invalid (the most common shell behavior) and treating the stray `[:'
as characters to be matched because they don't form a valid pattern (the
glibc behavior that Eduardo noted.)

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



Re: unalias works weirdly inside an if-then block

2017-05-18 Thread Ángel
I'm afraid you will have to rewrite the function just to get this
slightly different result (maybe you can source again that section of
the file?) :/



Re: unalias works weirdly inside an if-then block

2017-05-18 Thread DJ Mills
Why not unalias -a instead of simply going for cp? That way you know for a
fact that nothing has been changed


On Thu, May 18, 2017 at 8:59 PM, Ángel  wrote:

> I'm afraid you will have to rewrite the function just to get this
> slightly different result (maybe you can source again that section of
> the file?) :/
>
>


Infinite loop in readline's noninc_search

2017-05-18 Thread Eduardo Bustamante
Ran: bash -c 'read -e' < file # patched read to read from file

file Base64:

L/sFfwh+NRgqGHUcb39AfxsDAAACAIABIf+qANqAABsF6+M8KDyAAP7/qgDagAAbBevj
T0wgTYAnAAIAJgkJAAD+/6r///8JCQkAAAIA5vYJCQl6GzgAvBTgJf22G4A3/xuFhYWFhYVw
hYUXhYWFhYWF/xv/QHyAFAH/G/9AZIAyAQYbGVQE3i8UlhTelmQAGiIuVBAAwxQAABAAGVMkBHt7
e5ZiaXvPLxQCElMbGxAbGlOy/xtVgBQA+BsgRgTeLxSnFAAUGxoiGqEUJIbzlgTe1hQbGjyAAP7/
qvjagAAbBSIagP8JVBMbGxkAAAD/DBSUe3t7e3t7e94vQBuampqampqampqampqampqampoM
FJR/GwIMNRsbEP8aAGckKOEbIFQm3i8UABQbGxs4ADQbGiIaoRQkhvMCGxsQVCbeLxSW
BP7WFBsUIhqA/wlUExsbGQAAAP8MFJQUGwIbTiQuJA==


000   / 373 005 177  \b   ~   5 030   * 030   u 034   o 177   @ 177
020 033 003  \0  \0 002  \0 200 001   ! 377 252  \0 332 200  \0 033
040 005 353 343  \0  \0  \0   <   (   < 200  \0 376 377 252  \0 332
060 200  \0 033 005 353 343  \0  \0  \0   O   L   M 200  \0  \0
100  \0   '  \0 002  \0   &  \t  \t  \0  \0 376 377 252 377 377 377
120  \t  \t  \t  \0  \0 002  \0 346 366  \t  \t  \t   z 033   8  \0
140 274 024 340   % 375 266 033 200   7 377 033 205 205 205 205 205
160 205   p 205 205 027 205 205 205 205 205 205 377 033 377   @   |
200 200 024 001 377 033 377   @   d 200   2 001 006 033 031   T 004
220 336   / 024 226 024 336 226   d  \0 032   "   .   T 020  \0 303
240 024  \0  \0 020  \0 031   S   $ 004   {   {   { 226   b   i   {
260 317   / 024 002 022   S 033 033 020 033 032   S 262 377 033   U
300 200 024  \0 370 033   F 004 336   / 024 247 024  \0 024 033
320 032   " 032 241 024   $ 206 363 226 004 336 326 024 033 032   <
340 200  \0 376 377 252 370 332 200  \0 033 005   " 032 200 377  \t
360   T 023 033 033 031  \0  \0  \0 377  \f 024 224   {   {   {   {
400   {   {   { 336   /   @  \0  \0  \0 033 232 232 232 232 232 232
420 232 232 232 232 232 232 232 232 232 232 232 232  \f 024 224 177
440 033 002  \f   5 033 033 020 377  \0  \0  \0 032  \0   g   $   (
460 341 033   T   & 336   / 024  \0  \0  \0  \0 024 033 033 033
500   8  \0   4 033 032   " 032 241 024   $ 206 363 002 033 033 020
520   T   & 336   / 024 226 004 376 326 024 033 024   " 032 200 377
540  \t   T 023 033 033 031  \0  \0  \0 377  \f 024 224 024 033 002
560 033   N   $   .   $
565

(gdb) bt
#0  noninc_search (dir=1, pchar=0) at ../../../bash/lib/readline/search.c:377
#1  0x561e59f688a2 in rl_noninc_forward_search (count=1, key=110)
at ../../../bash/lib/readline/search.c:396
#2  0x561e59f62a47 in _rl_dispatch_subseq (key=110,
map=0x561e5a1d0160 , got_subseq=0)
at ../../../bash/lib/readline/readline.c:851
#3  0x561e59f627be in _rl_dispatch (key=1540448632,
map=0x561e5a1d0160 )
at ../../../bash/lib/readline/readline.c:797
#4  0x561e59f62984 in _rl_dispatch_subseq (key=78,
map=0x561e5a1d0160 , got_subseq=0)
at ../../../bash/lib/readline/readline.c:840
#5  0x561e59f62f0c in _rl_dispatch_subseq (key=27,
map=0x561e5a1cf140 , got_subseq=0)
at ../../../bash/lib/readline/readline.c:985
#6  0x561e59f627be in _rl_dispatch (key=1540448632,
map=0x561e5a1cf140 )
at ../../../bash/lib/readline/readline.c:797
#7  0x561e59f62446 in readline_internal_char () at
../../../bash/lib/readline/readline.c:629
#8  0x561e59f6249e in readline_internal_charloop () at
../../../bash/lib/readline/readline.c:656
#9  0x561e59f624c2 in readline_internal () at
../../../bash/lib/readline/readline.c:670
#10 0x561e59f61edf in readline (prompt=0x561e59fa6e0c "") at
../../../bash/lib/readline/readline.c:374
#11 0x561e59f3b40c in edit_line (p=0x561e59fa6e0c "", itext=0x0)
at ../../bash/builtins/../../bash/builtins/read.def:1090
#12 0x561e59f3a18e in read_builtin (list=0x0) at
../../bash/builtins/../../bash/builtins/read.def:554
#13 0x561e59ed29c7 in execute_builtin (builtin=0x561e59f39435
, words=0x561e5bcb3648, flags=64, subshell=0)
at ../bash/execute_cmd.c:4605
#14 0x561e59ed3927 in execute_builtin_or_function
(words=0x561e5bcb3648, builtin=0x561e59f39435 , var=0x0,
redirects=0x0, fds_to_close=0x561e5bcb2de8, flags=64) at
../bash/execute_cmd.c:5103
#15 0x561e59ed22a9 in execute_simple_command
(simple_command=0x561e5bcb2d08, pipe_in=-1, pipe_out=-1, async=0,
fds_to_close=0x561e5bcb2de8) at ../bash/execute_cmd.c:4391
#16 0x561e59ecb9df in execute_command_internal
(command=0x561e5bcb2cc8, asynchronous=0, pipe_in=-1, pipe_out=-1,
fds_to_close=0x561e5bcb2de8) at ../bash/execute_cmd.c:811
#17 0x561e59f32308 in parse_and_execute (string=0x561e5bc9b268
"PATH= read -e", from_file=0x561e59f8f630 "-c", flags=4)
at ../../bash/builtins/evalstring.c:430
#18 0x561e59eb2ce5 in run_one_command (command=0x7ffdabd84755
"PATH= read -e") at ../bash/shell.c:1405
#19 0x561e59eb1e04 in main (argc=3, argv=0x7ffdabd834d8,
env=0x7ffdabd834f8) at ../bash/shell.c:718

(gdb) info locals
cxt = 0x561e5bd16108
c = -1
r = 1

It seems like noninc_search doesn't handle EOF (-1) properly, the fix
seems to be:

d

AddressSanitizer: heap-use-after-free ../../../bash/lib/readline/display.c:2092 in update_line

2017-05-18 Thread Eduardo Bustamante
Run with: bash -c 'read -e' < file # patched bash

File base64:

KgMSGQX//wD/NBs1NTUbNRITNTU13TVGFgkVNTU1NdA1RhYJBTUzNdA1Rp4HB2BJYAcH9QcGAAAL
C2AzNdA1Rj0HB2BJBwYAAAsLAQBgYAIAgAiZgBVZYCAbAAEArq6urq6urq6urq6u/4Cu
rq6urq6urq6urq4AAWAZGRkZ5AAQGv9AoBsF

The error under ASAN:

==31690==ERROR: AddressSanitizer: heap-use-after-free on address
0x61d1a4b8 at pc 0x561a9673234b bp 0x7ffc6b8d0db0 sp
0x7ffc6b8d0da8
READ of size 4 at 0x61d1a4b8 thread T0
#0 0x561a9673234a in update_line ../../../bash/lib/readline/display.c:2092
#1 0x561a9672e589 in rl_redisplay ../../../bash/lib/readline/display.c:1121
#2 0x561a966f7aef in _rl_internal_char_cleanup
../../../bash/lib/readline/readline.c:514
#3 0x561a966f7ec5 in readline_internal_char
../../../bash/lib/readline/readline.c:638
#4 0x561a966f7ee2 in readline_internal_charloop
../../../bash/lib/readline/readline.c:656
#5 0x561a966f7f06 in readline_internal
../../../bash/lib/readline/readline.c:670
#6 0x561a966f75bc in readline ../../../bash/lib/readline/readline.c:374
#7 0x561a966b2991 in edit_line
../../bash/builtins/../../bash/builtins/read.def:1090
#8 0x561a966b0302 in read_builtin
../../bash/builtins/../../bash/builtins/read.def:554
#9 0x561a965c6a1d in execute_builtin ../bash/execute_cmd.c:4605
#10 0x561a965c8633 in execute_builtin_or_function ../bash/execute_cmd.c:5103
#11 0x561a965c5eb3 in execute_simple_command ../bash/execute_cmd.c:4391
#12 0x561a965b3db2 in execute_command_internal ../bash/execute_cmd.c:811
#13 0x561a9669d986 in parse_and_execute ../../bash/builtins/evalstring.c:430
#14 0x561a9657f271 in run_one_command ../bash/shell.c:1405
#15 0x561a9657d74a in main ../bash/shell.c:718
#16 0x7f7ce77c72b0 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
#17 0x561a9657c5b9 in _start
(/home/dualbus/src/gnu/bash-build-read-asan/bash+0x7f5b9)

0x61d1a4b8 is located 56 bytes inside of 2048-byte region
[0x61d1a480,0x61d1ac80)
freed by thread T0 here:
#0 0x7f7ce8035090 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc2090)
#1 0x561a9668c6a6 in xrealloc ../bash/xmalloc.c:133
#2 0x561a9672bc4c in rl_redisplay ../../../bash/lib/readline/display.c:966
#3 0x561a966f7aef in _rl_internal_char_cleanup
../../../bash/lib/readline/readline.c:514
#4 0x561a966f7ec5 in readline_internal_char
../../../bash/lib/readline/readline.c:638
#5 0x561a966f7ee2 in readline_internal_charloop
../../../bash/lib/readline/readline.c:656
#6 0x561a966f7f06 in readline_internal
../../../bash/lib/readline/readline.c:670
#7 0x561a966f75bc in readline ../../../bash/lib/readline/readline.c:374
#8 0x561a966b2991 in edit_line
../../bash/builtins/../../bash/builtins/read.def:1090
#9 0x561a966b0302 in read_builtin
../../bash/builtins/../../bash/builtins/read.def:554
#10 0x561a965c6a1d in execute_builtin ../bash/execute_cmd.c:4605
#11 0x561a965c8633 in execute_builtin_or_function ../bash/execute_cmd.c:5103
#12 0x561a965c5eb3 in execute_simple_command ../bash/execute_cmd.c:4391
#13 0x561a965b3db2 in execute_command_internal ../bash/execute_cmd.c:811
#14 0x561a9669d986 in parse_and_execute ../../bash/builtins/evalstring.c:430
#15 0x561a9657f271 in run_one_command ../bash/shell.c:1405
#16 0x561a9657d74a in main ../bash/shell.c:718
#17 0x7f7ce77c72b0 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

previously allocated by thread T0 here:
#0 0x7f7ce8035090 in realloc
(/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc2090)
#1 0x561a9668c6a6 in xrealloc ../bash/xmalloc.c:133
#2 0x561a9672bc4c in rl_redisplay ../../../bash/lib/readline/display.c:966
#3 0x561a966f7aef in _rl_internal_char_cleanup
../../../bash/lib/readline/readline.c:514
#4 0x561a966f7ec5 in readline_internal_char
../../../bash/lib/readline/readline.c:638
#5 0x561a966f7ee2 in readline_internal_charloop
../../../bash/lib/readline/readline.c:656
#6 0x561a966f7f06 in readline_internal
../../../bash/lib/readline/readline.c:670
#7 0x561a966f75bc in readline ../../../bash/lib/readline/readline.c:374
#8 0x561a966b2991 in edit_line
../../bash/builtins/../../bash/builtins/read.def:1090
#9 0x561a966b0302 in read_builtin
../../bash/builtins/../../bash/builtins/read.def:554
#10 0x561a965c6a1d in execute_builtin ../bash/execute_cmd.c:4605
#11 0x561a965c8633 in execute_builtin_or_function ../bash/execute_cmd.c:5103
#12 0x561a965c5eb3 in execute_simple_command ../bash/execute_cmd.c:4391
#13 0x561a965b3db2 in execute_command_internal ../bash/execute_cmd.c:811
#14 0x561a9669d986 in parse_and_execute ../../bash/builtins/evalstring.c:430
#15 0x561a9657f271 in run_one_command ../bash/shell.c:1405
#16 0x561a9657d74a in main ../bash/shell.c:718
#17 0x7f7ce77c72b0 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

SUMMARY: AddressSanitizer: heap-use-after-free
../../../bash/lib/readline/display.c:2092