Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 327d2b9ae4dfd6cf1ec2ac05cc629db7662ea4e9cfb629246db1979dee1554e6
Ticket: 2511011fffffffffffffffffffffffffffffffff
[glob] can return non-existing filenames
User & Date: sebres on 2018-04-09 15:29:35
Changes

  1. closer changed to: "nobody"
  2. comment changed to:
    glob doesn't escape filenames starting with ~. This means glob by default can return filenames that 1) don't exists (annoying) or even point to a different spot all together (a user directory for instance, which is outright dangerous). 
    
    For example:
    create a file name "~test"
    
    % foreach file [glob *] { if {![file exists $file]} {puts "huh $file doesn't exists"}}
    huh ~test doesn't exists
    % info pa
    8.5.4
    
    Interactive session above was with Tcl 8.5.4.
    Dangerous situations can occur if a filename matches a valid user directory (~ for instance) and results of glob are used in recursive delete operations (which would lead to removal of the users home dir in this case)
    
    It seems that me that glob should properly escape ~ as "./~test".
    
  3. icomment:
    I think either we should "fix" this or provide a fix for `filename-11.42`, because of annoying sporadic test fails within: if the test-suite runs in the temp-folder it can contains some files like `$::env(tmp)/~DF670D65B85835F8E2.TMP` (e. g. very often on windows platform). So this test-case will always fail there, because $res never equal `[glob *]` there.
    
    Additionally, I believe `[glob *]` is basically nothing other as `[glob -tails -directory [pwd] *]`, because both returns relative paths.
    But ATM both do not real `file tail` (at least in sense of Tcl's file tail), so e. g. in case of filename-11.42 it works wrong - you'll get `~DF67.TMP` instead of `./~DF67.TMP`.
    
    BTW, it is very weird as it's currently implemented. 
    For example this fully legal simple code will fail, if contain such files (with "User DF67.TMP doesn't exist"):
    
      foreach fn [glob -tails -directory [pwd] *] {
        puts "touch $fn"
        close [open $fn r]
      }
    
    But this one (quasi doing the same) runs successfully:
    
      set res [list]
      foreach f [glob -dir [pwd] -types f *] {
        lappend res [file tail $f]
      }
      foreach fn $res {
        puts "touch $fn"
        close [open $fn r]
      }
    
    I'm for fixing glob for both cases (`glob *` as well as `glob -dir [pwd] -tails *`).
    Because IMHO it must return correct relative path!
    
  4. login: "sebres"
  5. mimetype: "text/plain"
  6. severity changed to: "Minor"