helpThe GNU Bourne-Again SHell - Support: sr #109671, Regression: Initial quoted...

 
 

sr #109671: Regression: Initial quoted substitution of variable stripped to empty causes [[ stat tests to yield incorrect results

Submitted by:  Matt Whitlock <mwhitlock>
Submitted on:  Wed 10 Apr 2019 07:50:31 PM UTC  
 
Category:  None Priority:  5 - Normal
Severity:  4 - Important Status:  Done
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 11 Apr 2019 03:56:19 PM UTC, comment #1: 

This will be fixed in the next devel branch push.

Chet Ramey <chet>
Project Administrator
Wed 10 Apr 2019 07:50:31 PM UTC, original submission:  

bug() {
    [[ -d ${1}/tmp ]] ; echo -n $?
    [[ -d "${1}/tmp" ]] ; echo -n $?
    [[ -d "${1}"/tmp ]] ; echo -n $?
    [[ -d ${1%/}/tmp ]] ; echo -n $?
    [[ -d "${1%/}/tmp" ]] ; echo -n $?
    [[ -d "${1%/}"/tmp ]] ; echo $?
}

All of the above tests should yield the same result for any given argument, yet…

$ bug ; bug '' ; bug / ; bug /var ; bug /var/
000000
000000
000001
000000
000000

Whoops. :(

strace reveals that Bash is actually trying to stat "\177/tmp" in the failed case:

stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0\n", 2)                      = 2
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0\n", 2)                      = 2
stat("//tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("//tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("//tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=540, ...}) = 0
write(1, "0", 1)                        = 1
stat("\177/tmp", 0x7ffd4b1750c0)        = -1 ENOENT (No such file or directory)
write(1, "1\n", 2)                      = 2
stat("/var/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0", 1)                        = 1
stat("/var/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0", 1)                        = 1
stat("/var/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0", 1)                        = 1
stat("/var/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0", 1)                        = 1
stat("/var/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0", 1)                        = 1
stat("/var/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0\n", 2)                      = 2
stat("/var//tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0", 1)                        = 1
stat("/var//tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0", 1)                        = 1
stat("/var//tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0", 1)                        = 1
stat("/var/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0", 1)                        = 1
stat("/var/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0", 1)                        = 1
stat("/var/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=315, ...}) = 0
write(1, "0\n", 2)                      = 2

Matt Whitlock <mwhitlock>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by mwhitlock (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-04-11 chet StatusNone => Done

    Back to the top


    Powered by Savane 3.5