Re: Bug in Bash Autocompletion: Hidden File, ...Hiding-From-You, Autocompleted Without Dot Prefix

2025-04-25 Thread Robert Elz
Date:Fri, 25 Apr 2025 15:44:47 -0400
From:Chet Ramey 
Message-ID:  <9d1a2482-d47f-4c49-9581-45c5db81d...@case.edu>

  | I can't reproduce this using bash-5.2.37.

I can.

  | I suspect this is the result your
  | programmable completion specification for `cat' produces.

I suspect it is more likely that the readline config option
"match-hidden-files" is "on" (which seems to be its default).

With that turned off, things work as expected by the OP.

kre





Bug in Bash Autocompletion: Hidden File, ...Hiding-From-You, Autocompleted Without Dot Prefix

2025-04-25 Thread Tanmay Jagtap
*Dear Bash Maintainers,*

I have encountered an issue with Bash autocompletion on my system.
Specifically, a file beginning with three dots (e.g., ...Hiding-From-You)
is autocompleted even when no dot (.) has been typed, which seems
inconsistent with typical Bash behavior where hidden files are excluded
from completion unless the input starts with a dot.

Here’s how to reproduce the issue:
# Setup
mkdir ~/bash-bug-test
cd ~/bash-bug-test
touch ...hiddenfile

# Now test
cat 

*Expected Behavior:*
No suggestions should appear as the input does not start with a dot (.).

*Actual Behavior:*
The file ...hiddenfile is autocompleted even though no dot was typed.
Environment Info:
bash --version
# GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
# Copyright (C) 2022 Free Software Foundation, Inc.

uname -a
# Linux bandit 6.8.0-1026-aws #28-Ubuntu SMP Mon Mar 24 19:32:19 UTC 2025
x86_64 x86_64 x86_64 GNU/Linux

gcc --version
# gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0

ldd $(which bash)
# linux-vdso.so.1 (0x77fc3000)
# libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x77e15000)
# libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x77c0)
# /lib64/ld-linux-x86-64.so.2 (0x77fc5000)
Note: libreadline is *not linked*, suggesting this Bash binary may not be
using readline, which may be relevant for the autocompletion issue.
Please feel free to mention my email (j.t4nma...@gmail.com) or Github
Username (TammyWho) if this bug is acknowledged or fixed.

Thank you for your time and for maintaining Bash!


Re: Bug in Bash Autocompletion: Hidden File, ...Hiding-From-You, Autocompleted Without Dot Prefix

2025-04-25 Thread Tanmay Jagtap
Thanks, I'll check it out.

On Sat, 26 Apr 2025, 1:14 am Chet Ramey,  wrote:

> On 4/25/25 11:18 AM, Tanmay Jagtap wrote:
> > *Dear Bash Maintainers,*
> >
> > I have encountered an issue with Bash autocompletion on my system.
> > Specifically, a file beginning with three dots (e.g., ...Hiding-From-You)
> > is autocompleted even when no dot (.) has been typed, which seems
> > inconsistent with typical Bash behavior where hidden files are excluded
> > from completion unless the input starts with a dot.
>
> I can't reproduce this using bash-5.2.37. I suspect this is the result your
> programmable completion specification for `cat' produces.
>
> You can find out the completion specification for cat by running
> `complete -p cat'.
>
>
> > ldd $(which bash)
> > # linux-vdso.so.1 (0x77fc3000)
> > # libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6
> (0x77e15000)
> > # libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x77c0)
> > # /lib64/ld-linux-x86-64.so.2 (0x77fc5000)
> > Note: libreadline is *not linked*, suggesting this Bash binary may not be
> > using readline, which may be relevant for the autocompletion issue.
>
> It's more likely that it means your version of bash is linked against the
> static version of readline that is part of the bash distribution.
>
> Chet
>
> --
> ``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/
>


Re: Bug in Bash Autocompletion: Hidden File, ...Hiding-From-You, Autocompleted Without Dot Prefix

2025-04-25 Thread Chet Ramey

On 4/25/25 11:18 AM, Tanmay Jagtap wrote:

*Dear Bash Maintainers,*

I have encountered an issue with Bash autocompletion on my system.
Specifically, a file beginning with three dots (e.g., ...Hiding-From-You)
is autocompleted even when no dot (.) has been typed, which seems
inconsistent with typical Bash behavior where hidden files are excluded
from completion unless the input starts with a dot.


I can't reproduce this using bash-5.2.37. I suspect this is the result your
programmable completion specification for `cat' produces.

You can find out the completion specification for cat by running
`complete -p cat'.



ldd $(which bash)
# linux-vdso.so.1 (0x77fc3000)
# libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x77e15000)
# libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x77c0)
# /lib64/ld-linux-x86-64.so.2 (0x77fc5000)
Note: libreadline is *not linked*, suggesting this Bash binary may not be
using readline, which may be relevant for the autocompletion issue.


It's more likely that it means your version of bash is linked against the
static version of readline that is part of the bash distribution.

Chet

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


OpenPGP_signature.asc
Description: OpenPGP digital signature


SourceAv in xparse_dolparen when trying to compare with rvalue

2025-04-25 Thread Александр Ушаков

Dear Bash Maintainers,
I encountered an issue in Bash and would like to report it. crash3.txt is 
attached to the email. So this problem also appers after require my fix in my 
previous letter (SourceAv in rewind_input_string when trying to compare with 
rvalue). But I found other input data (crash3.txt) for triggering this SEGV 
(bypass SEGV in rewind_input_string). 

Steps to reproduce

$ CC=clang-19 CFLAGS="-fsanitize=address -g -O0" ./configure 
--without-bash-malloc
$ make
$ cat crash3.txt | ./bash 

Expected Behaviour

Any error messages without asan ERROR.

Actual Behaviour
AddressSanitizer:DEADLYSIGNAL 
= 
==2334452==ERROR: AddressSanitizer: SEGV on unknown address 0x9fff7fff (pc 
0x556fe4a4 bp 0x7fffb6b0 sp 0x7f
ffb4c0 T0) 
==2334452==The signal is caused by a READ memory access. 
  #0 0x556fe4a4 in xparse_dolparen 
/home/as/projects/bash/up/bash/./parse.y:4775:7 
  #1 0x55789ee2 in extract_command_subst 
/home/as/projects/bash/up/bash/subst.c:1271:13 
  #2 0x55792275 in skip_double_quoted 
/home/as/projects/bash/up/bash/subst.c:1053:12 
  #3 0x557943c4 in skip_matched_pair 
/home/as/projects/bash/up/bash/subst.c:2147:8 
  #4 0x557930db in skipsubscript 
/home/as/projects/bash/up/bash/subst.c:2186:11 
  #5 0x557157e4 in assignment 
/home/as/projects/bash/up/bash/general.c:509:11 
  #6 0x5570c0da in read_token_word 
/home/as/projects/bash/up/bash/./parse.y:5772:7 
  #7 0x55704a1d in read_token 
/home/as/projects/bash/up/bash/./parse.y:3801:12 
  #8 0x556f8390 in yylex /home/as/projects/bash/up/bash/./parse.y:3068:19 
  #9 0x556ee897 in yyparse /home/as/projects/bash/up/bash/y.tab.c:1912:16 
  #10 0x556edd29 in parse_command 
/home/as/projects/bash/up/bash/eval.c:369:7 
  #11 0x556ed53e in read_command 
/home/as/projects/bash/up/bash/eval.c:414:12 
  #12 0x556ec9ec in reader_loop 
/home/as/projects/bash/up/bash/eval.c:147:11 
  #13 0x556e743e in main /home/as/projects/bash/up/bash/shell.c:834:3 
  #14 0x77cac249 in __libc_start_call_main 
csu/../sysdeps/nptl/libc_start_call_main.h:58:16 
  #15 0x77cac304 in __libc_start_main csu/../csu/libc-start.c:360:3 
  #16 0x55606aa0 in _start (/home/as/projects/bash/up/bash/bash+0xb2aa0) 
(BuildId: de2fc7db85184fa111505879caea6faa2d
9470c4)
==2334452==Register values: 
rax = 0x1fff  rbx = 0x7fffb4c0  rcx = 0x  
rdx = 0x014c   
rdi = 0x778dc050  rsi = 0x778dc0d0  rbp = 0x7fffb6b0  
rsp = 0x7fffb4c0   
r8 = 0x05f0   r9 = 0x5240  r10 = 0x7f01  
r11 = 0x734571579d1e8501   
r12 = 0x  r13 = 0x7fffde98  r14 = 0x55a1afd0  
r15 = 0x77ffd020   
AddressSanitizer can not provide additional info. 
SUMMARY: AddressSanitizer: SEGV /home/as/projects/bash/up/bash/./parse.y:4775:7 
in xparse_dolparen 
==2334452==ABORTING
 

Additional Notes

The reason of the fault is trying to dereference object which is nullptr: 
  /* Need to find how many characters parse_string() consumed, update
    *indp, if flags != 0, copy the portion of the string parsed into RET
    and return it.  If flags & 1 (SX_NOALLOC) we can return NULL. */
        /*(*/
-->  if (ep[-1] != ')')
           {
           #if 0

Suggested Solution

Add extra check in conditional statement:

 /*(*/
 if (!ep) { return (char *)NULL;} 
 if (ep[-1] != ')')
   {


Bash Version

as@astra:~/projects/bash/up/bash$ ./bashversion 
5.3.0(1)-rc1

Also, the behaviour is repeating on release bash 5.2 version.

System Info

Linux astra 6.1.90-1-generic #astra2+ci15 SMP PREEMPT_DYNAMIC Tue Jul 23 
09:49:19 MSK 2024 x86_64 GNU/Linux
Debian clang version 19.1.1 
(++20241001124028+d401987fe349-1~exp1~20241001124040.50) 
Target: x86_64-pc-linux-gnu 
Thread model: posix 
InstalledDir: /usr/lib/llvm-19/bin

Attached file you can download from https://dropmefiles.com/rPfwa. Or just see 
attaches to the message.
f[8"è0ÿ0
usï]íx=10 f $$(
 0ÿ0
usï]íí   exec {fé[1]}>&1ííííííííííííííííUT UT ANY 
f[8"è $10:Îaaa>9& modify
#-7 ))>))d);
ser 
x=1 f $$(
 0ÿ0
usaa
axNy=("$
y=("$]%
[#   This program is free software: you can redistributed=$(cat <.
#
SAVEPWD=$PWD
: ${TMPDIR:=/tmp}
cd $TMPDIR || echo "heredoc3.sub: cannot cd to $TMPDIR" >&2

text=$(cat .
#
SAVEPWD=$PWD
: ${TMPDIR:=/tmp}
cd $TMPDIR || echo "heredoc3.sub: cannot cd to $TMPDIR" >&2

text=$(cat 

SourceAv in rewind_input_string when trying to compare with rvalue

2025-04-25 Thread Александр Ушаков

Dear Bash Maintainers,
I encountered an issue in Bash and would like to report it. crash2.txt is 
attached to the email. 

Steps to reproduce

$ CC=clang-19 CFLAGS="-fsanitize=address -g -O0" ./configure 
--without-bash-malloc
$ make
$ cat crash2.txt | ./bash 

Expected Behaviour

Any error messages without asan ERROR.

Actual Behaviour

==2054281==ERROR: AddressSanitizer: SEGV on unknown address 0x9fff7fff (pc 
0x556f8b1c bp 0x7fff7df0 sp 0x7fff7de0 T0)
==2054281==The signal is caused by a READ memory access.
   #0 0x556f8b1c in rewind_input_string 
/home/as/projects/bash/up/bash/./parse.y:1816:7
   #1 0x558711b3 in parse_string 
/home/as/projects/bash/up/bash/builtins/evalstring.c:729:6
   #2 0x556fe39d in xparse_dolparen 
/home/as/projects/bash/up/bash/./parse.y:4738:8
   #3 0x55789ee2 in extract_command_subst 
/home/as/projects/bash/up/bash/subst.c:1271:13
   #4 0x5578b175 in extract_delimited_string 
/home/as/projects/bash/up/bash/subst.c:1429:15
   #5 0x5578b51a in extract_delimited_string 
/home/as/projects/bash/up/bash/subst.c:1449:8
   #6 0x5578b51a in extract_delimited_string 
/home/as/projects/bash/up/bash/subst.c:1449:8
   #7 0x5578b5ec in extract_delimited_string 
/home/as/projects/bash/up/bash/subst.c:1459:8
   #8 0x557945b2 in skip_matched_pair 
/home/as/projects/bash/up/bash/subst.c:2158:13
   #9 0x557930db in skipsubscript 
/home/as/projects/bash/up/bash/subst.c:2186:11
   #10 0x557157e4 in assignment 
/home/as/projects/bash/up/bash/general.c:509:11
   #11 0x55711b33 in token_is_assignment 
/home/as/projects/bash/up/bash/./parse.y:5269:7
   #12 0x5570a27e in read_token_word 
/home/as/projects/bash/up/bash/./parse.y:5638:15
   #13 0x55704a1d in read_token 
/home/as/projects/bash/up/bash/./parse.y:3801:12
   #14 0x556f8390 in yylex /home/as/projects/bash/up/bash/./parse.y:3068:19
   #15 0x556ee897 in yyparse /home/as/projects/bash/up/bash/y.tab.c:1912:16
   #16 0x55710e41 in parse_comsub 
/home/as/projects/bash/up/bash/./parse.y:4539:7
   #17 0x55710322 in parse_matched_pair 
/home/as/projects/bash/up/bash/./parse.y:4163:16
   #18 0x55709f64 in read_token_word 
/home/as/projects/bash/up/bash/./parse.y:5624:11
   #19 0x55704a1d in read_token 
/home/as/projects/bash/up/bash/./parse.y:3801:12
   #20 0x556f8390 in yylex /home/as/projects/bash/up/bash/./parse.y:3068:19
   #21 0x556ee897 in yyparse /home/as/projects/bash/up/bash/y.tab.c:1912:16
   #22 0x556edd29 in parse_command 
/home/as/projects/bash/up/bash/eval.c:369:7
   #23 0x556ed53e in read_command 
/home/as/projects/bash/up/bash/eval.c:414:12
   #24 0x556ec9ec in reader_loop 
/home/as/projects/bash/up/bash/eval.c:147:11
   #25 0x556e743e in main /home/as/projects/bash/up/bash/shell.c:834:3
   #26 0x77cac249 in __libc_start_call_main 
csu/../sysdeps/nptl/libc_start_call_main.h:58:16
   #27 0x77cac304 in __libc_start_main csu/../csu/libc-start.c:360:3
   #28 0x55606aa0 in _start (/home/as/projects/bash/up/bash/bash+0xb2aa0) 
(BuildId: de2fc7db85184fa111505879caea6faa2d9470c4)
==2054281==Register values:
rax = 0x1fff  rbx = 0x7fff7fe0  rcx = 0x563c5820  
rdx = 0x013b  
rdi = 0x778dc050  rsi = 0x778dc0d0  rbp = 0x7fff7df0  
rsp = 0x7fff7de0  
r8 = 0x0020   r9 = 0x52454000  r10 = 0x7f01  
r11 = 0x22901ec408173e01  
r12 = 0x  r13 = 0x7fffde98  r14 = 0x55a1afd0  
r15 = 0x77ffd020  
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /home/as/projects/bash/up/bash/./parse.y:1816:7 
in rewind_input_string
==2054281==ABORTING

Additional Notes

The reason of the fault is trying to dereference string field which is nullptr:
 
void
rewind_input_string ()
{
     int xchars;
     /* number of unconsumed characters in the input -- XXX need to take 
newlines
    into account, e.g., $(...\n) */
    xchars = shell_input_line_len - shell_input_line_index;
-->if (bash_input.location.string[-1] == '\n')
         xchars++;

Suggested Solution

Add extra check in conditional statement:

if (!bash_input.location.string && bash_input.location.string[-1] == '\n')


Bash Version

as@astra:~/projects/bash/up/bash$ ./bashversion 
5.3.0(1)-rc1

Also, the behaviour is repeating on release bash 5.2 version.

System Info

Linux astra 6.1.90-1-generic #astra2+ci15 SMP PREEMPT_DYNAMIC Tue Jul 23 
09:49:19 MSK 2024 x86_64 GNU/Linux
Debian clang version 19.1.1 
(++20241001124028+d401987fe349-1~exp1~20241001124040.50) 
Target: x86_64-pc-linux-gnu 
Thread model: posix 
InstalledDir: /usr/lib/llvm-19/bin

Attached file you can download from https://dropmefiles.com/deEbb. Or just see 
attaches to the message.
aá;ray[%(( 1001 - $( ec5 &
sleep&3 .arranty of
#  #نk >&-9p 5 &
sle 5 &
sleep #   Thim is free software: you can redistribute it and/or modify
#$  it under the te