Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-22
17:19 • Ticket [1048733fff] possible segfaults with NULL interps status still Closed... artifact: 1586797593 user: serhiy.storchaka
2026-10-21
10:03 • Closed ticket [1048733fff]. artifact: c8ab81d8e1 user: serhiy.storchaka
2006-03-10
13:40 • Ticket [1048733fff]: 4 changes artifact: f06442447c user: dgp
2004-10-18
16:55 • Ticket [1048733fff]: 6 changes artifact: 48c2e07002 user: vincentdarley
00:30 • Ticket [1048733fff]: 4 changes artifact: b74ce92ec3 user: coldstore
00:16 • Ticket [1048733fff]: 4 changes artifact: 5dcbb485ef user: coldstore
2004-10-17
16:36 • New ticket [1048733fff]. artifact: 06f201323c user: coldstore

possible segfaults with NULL interps

Closed / Fixed1048733fffffffffffffffffffffffffffffffffCreated 22 years agoUpdated 41 days ago
Descriptionplain2004-10-17 16:36:45
FileCopyRename at ../generic/tclFCmd.c:539 calls
Tcl_FSFileAttrsSet(NULL, 2, target, perm), passing a
NULL Tcl_Interp* into the set attr command (presumably
because the rename is being performed en passant)

However, NativeFileAttrsSet() which is the default for
normal file systems (and other set attribute handlers),
can get errors - in my case in SetPermissionsAttribute
at ../unix/tclUnixFCmd.c:1480, where a posix error
occurs, and the code calls Tcl_PosixError(interp).

The upshot is that Tcl_PosixError tries (eventually) to
set errorCode and this fails because there is no
interpreter (or, rather, a NULL interpreter) for it to
set the variable in.

You can reproduce this by creating a pair of files, A
and B, owned by another user and (at least in my case)
chmod u=rw,g=r,o=r

Then, in tclsh8.5:  file rename -force A B

It SIGSEGVs because of the NULL interpreter.

I suggest that the practice of passing NULL interp into
functions which could generate errors is always bad,
and in this case at least the call to
Tcl_FSFileAttrsSet should pass in the variable interp,
and not NULL.
coldstoreplain2004-10-18 00:16:32
Logged In: YES 
user_id=19214

At least the following public and private functions in
tcl/generic/ match the following criteria:

1) have Tcl_Interp* as their first argument
2) have NULL passed in as their first argument.

In the case that they (or the functions they pass interp to)
can possibly error, I believe there's a risk of a segment fault.

Tcl_Close Tcl_DictObjFirst Tcl_DictObjGet Tcl_DictObjPut
Tcl_DictObjRemove Tcl_DictObjSize Tcl_ExternalToUtf
Tcl_FSConvertToPathType Tcl_FSFileAttrsSet Tcl_FSGetCwd
Tcl_FSGetNormalizedPath Tcl_FSGetTranslatedPath
Tcl_FSJoinToPath Tcl_FSOpenFileChannel Tcl_GetBoolean
Tcl_GetBooleanFromObj Tcl_GetEncoding Tcl_GetIndexFromObj
Tcl_GetInt Tcl_GetIntFromObj Tcl_GetLongFromObj
Tcl_GetWideIntFromObj Tcl_ListObjAppendElement
Tcl_ListObjAppendList Tcl_ListObjGetElements
Tcl_ListObjIndex Tcl_ListObjLength Tcl_ListObjReplace
Tcl_ParseCommand Tcl_RegExpCompile Tcl_SetChannelOption
Tcl_SplitList Tcl_UtfToExternal

CheckForDeadChannel DoTildeSubst FlushChannel GetStatBuf
SetBlockMode SetByteArrayFromAny SetFsPathFromAny
SetStringFromAny
coldstoreplain2004-10-18 00:30:05
Logged In: YES 
user_id=19214

Winnowing out those functions which document that the can
accept NULL interp arguments, we're left with these
candidates for SEGV:

Tcl_FSConvertToPathType
Tcl_FSFileAttrsSet
Tcl_FSGetCwd
Tcl_FSGetNormalizedPath
Tcl_FSGetTranslatedPath
Tcl_FSJoinToPath
Tcl_FSOpenFileChannel
Tcl_GetBoolean
Tcl_GetBooleanFromObj
Tcl_GetEncoding
Tcl_GetIndexFromObj
Tcl_GetInt
Tcl_GetIntFromObj
Tcl_GetLongFromObj
Tcl_GetWideIntFromObj
Tcl_SetChannelOption
CheckForDeadChannel
DoTildeSubst
FlushChannel
GetStatBuf
SetBlockMode
SetByteArrayFromAny
SetFsPathFromAny
SetStringFromAny
vincentdarleyplain2004-10-18 16:55:29
Logged In: YES 
user_id=32170

The segfault cited has been fixed in cvs head a few weeks back.

It would be worth looking at the other possible problems in
more detail.
dgpplain2006-03-10 13:40:55
Logged In: YES 
user_id=80530


where do we stand on this now?
serhiy.storchakawiki2026-10-21 10:03:39

The reported crash (file rename -force calling Tcl_FSFileAttrsSet() with a NULL interp) was fixed in 8.5.0 by [088b6e6a3c] ([1020538]): the Unix attribute setters no longer touch a NULL interp on error. No crash with the other listed functions has been reported, so closing.

serhiy.storchaka Ticket [1048733fff]: 3 changes [History diff]2026-10-22 17:19:32
Log in (anonymous is fine) to add a comment.