Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Win TclpObjNormalizePath fails for non-existent drive

Closed / Fixed3603434fffffffffffffffffffffffffffffffffCreated 14 years agoUpdated 14 years ago
Descriptionplain2013-02-05 16:38:31
The portions of filesystem pathname handling in
the generic/*.c files of Tcl include special per-platform
handling of [file pathtype] queries.  In particular, on
Windows, any pathname starting with ?:/ , where ?
is any single byte, gets labeled as an absolute path
based on the assumption that it's a drive designation.
This happens whether or not such a drive is actually
on the system.

Over in the tclWinFile.c implementation of
TclpObjNormalizePath(), though, a normalization
of  a path of the same pattern, say "a:/", is more
constrained.  If the "a" drive is not actually on
the system (floppy drives are uncommon now),
it refuses to declare that "a:/" is a normalized
pathname.  Instead, it claims "a:" is a normalized
pathname, and leaves the rest for other filesystems
to continue normalizing.  This is trouble and inconsistent.
The cooperative normalization process relies on working
on an absolute pathname, and this misstep leaves us
with a volumerelative one.  It's also inconsistent with the
rules imposed in the generic code.

Most of the time this bug is harmless, because no other
filesystem is present or makes an effort to claim, and the
final fallback is to give it native ownership and just assume
what's left is normalized.  This turns out to be correct.  The
only time this causes trouble is when the 
Tcl_FSNormalizePathProc of some other Tcl_Filesystem
recursively calls for a prefix of the path to be normalized
as part of its own attempt to normalize more of the path.
For example, this is what trofs does.  Then the bug leads
to endless recursion and a crash when the stack is exhausted.
Thanks to Brian Griffin for taking notice of this.  Demonstration
isn't difficult.  On Windows, bring trofs into an interp and then
attempt a [glob a:/] on a system with no A: drive.  CRASH!

The simplest way to restore consistency is to make sure 
TclpObjNormalizePath claims the first / in the path as part
of a normalized path, whether or not the drive exists on
the system.  Then the assumptions of the cooperative
normalization among Tcl_Filesystems are maintained and
crashes are avoided.

To be clear, this is not the "most correct" solution.  Getting
something more correct involves some serious rewriting so
that platform processing is better contained in platform files.
This is a minimal consistency and sanity and crash prevention
fix given the state of things as they are.
dgpplain2013-02-05 23:47:54
Fix is on branch bug-3603434
dgpplain2013-02-05 23:56:44
Fix merged to all active branches.
dgpplain2013-02-05 23:56:45
allow_comments - 1
Log in (anonymous is fine) to add a comment.