Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Core Dump when setting const with non-existent namespace

Closed / Fixed4b22d84a6236ed01b4ba300556dc4f4c78214ee0Created 326 days agoUpdated 263 days ago
Descriptionmarkdown2026-01-11 00:18:40

System: Red Hat 8.10
TCL was compiled from source
config switches: ./configure --disable-shared

Example:

const ::test::test 1
Segmentation fault (core dumped)

If a namespace in question already exists, there are no issues.

Referenced by1
stuplain2026-03-13 11:35:56
Index: generic/tclExecute.c
--- generic/tclExecute.c.orig
+++ generic/tclExecute.c
@@ -4214,6 +4214,11 @@ TEBCresume(
 	TRACE("\"%.30s\" \"%.30s\" => ", O2S(part1Ptr), O2S(objPtr));
 	varPtr = TclObjLookupVarEx(interp, part1Ptr, NULL, 0, NULL,
 		/*createPart1*/1, /*createPart2*/0, &arrayPtr);
+	if (!varPtr) {
+	    /* Maybe use TCL_LEAVE_ERR_MSG in the lookup call? */
+	    msgPart = "problem!";
+	    goto constError;
+	}
     doConst:
 	if (TclIsVarConstant(varPtr)) {
 	    TRACE_APPEND("already constant\n");
stuplain2026-03-13 11:36:54
There should be a test for this as well.
apnadkarniplain2026-03-13 14:26:51
Proposed fix in [ba4d418633].
stuplain2026-03-13 17:32:53
Not "goto constError;" or even "goto gotError;" ?

That seems to be the normal exit route.
apnadkarniplain2026-03-13 18:03:19
@stu, which line are you referring to? It does do "goto gotError".
stuplain2026-03-13 18:28:06
Ok, so the link in your message isn't or is only part of the fix.
These are the changes I thought I'd see [cfc42afaa005ed5d].
stuplain2026-03-13 18:29:36
Also, looks like the code in that file does:
if (!varPtr)
not:
if (varPtr == NULL)
stuplain2026-03-13 18:37:36
Also, if TCL_LEAVE_ERR_MSG is being used, isn't there a way to get that result and put it into msgPart, which should probably be set anyway?

Also also, "variable not found" isn't the right error.

In the testcase, the error returned is "parent namespace doesn't exist" - who knows what other errors could be returned?

I think the way to go is to put the interp result err string into msgPart then jump to constError.
apnadkarniplain2026-03-14 02:33:10
I don't want to jump to constError because it uses other variables whose status I do not know on the jump to doConst (remember varPtr was not set) and I do not want to trace backward to jump points.

"variable not found" is only used if the interpreter does not already have an error message. If it does, it is preserved (which again, is not the case with constError).

Setting msgPart is not trivial because it expects a static string. Pointing it to content of interp result requires more book keeping.

Also note constError is only used in that code block for errors related to arrays. Otherwise gotError is used (see the line 3692 in the last code block before constError.

I do not use ! with pointers. Stylistic choice. Shrug.
apnadkarni Closed ticket [4b22d84a62]. [History diff]2026-03-14 10:32:00
stuplain2026-03-14 13:08:28
TclExecute.c has
4 "if (varPtr == NULL)"
8 "if (!varPtr)"

*not-too-impressed-shrug*
Log in (anonymous is fine) to add a comment.