Skip to content
Tcl Source Code View Ticket
Login

View Ticket

"exec cat foo > ~unknown_user" == crash

Closed / Fixed1352409fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-11-09 17:49:22
You can trigger a crash by:

exec cat foo > ~unknown_user

The problem is a Tcl_DStringFree on an unallocated 
Tcl_DString in FileForRedirect in tclPipe.c. The 
Tcl_DStringFree then tries to ckfree a garbage value - 
bang!


Something like:

--- orig\tclPipe.c      2005-10-28 12:24:40.515898100 
+0100
+++ tclPipe.c   2005-11-09 17:42:32.411874900 +0000
@@ -136,10 +136,10 @@
        name = Tcl_TranslateFileName(interp, spec, 
&nameString);
        if (name != NULL) {
            file = TclpOpenFile(name, flags);
+           Tcl_DStringFree(&nameString);
        } else {
            file = NULL;
        }
-       Tcl_DStringFree(&nameString);
        if (file == NULL) {
            Tcl_AppendResult(interp, "couldn't ",
                    ((writing) ? "write" : "read"), " file \"", 
spec, "\": ",




...should fix it.
nobodyplain2005-11-10 17:10:17
Logged In: NO 

Also while 8.4 may not have the bug, it still gives a mixed up 
error message:

% info patchlevel
8.4.8
% exec cat foo > ~unknown_user
user "unknown_user" doesn't existcouldn't write 
file "~unknown_user": No error
%
nobodyplain2005-11-29 17:44:52
Logged In: NO 

Also note that if the Tcl_TranslateFileName() fails 
(returns NULL), then it should have it's own error message 
as the existing one contains Tcl_PosixError which won't 
have been set.
nobodyplain2006-02-07 19:23:12
Logged In: NO 

NB. this is now fixed by v1.17 of tclpipe.c :

* generic/tclPipe.c (FileForRedirect): Prevent nameString
from being freed without having been initialized.
hobbs Closed ticket [1352409fff]. [History diff]2006-02-08 01:23:25
Log in (anonymous is fine) to add a comment.