Tcl Source Code

View Ticket
Login
2026-03-14
13:08 • Ticket [4b22d84a62] Core Dump when setting const with non-existent namespace... artifact: f08f25a55b user: stu
10:32 • Closed ticket [4b22d84a62]. artifact: ccc86370e4 user: apnadkarni
10:30
Merge 9.0 - Fix [4b22d84a] - const crash if undefined namespace check-in: d513896977 user: apnadkarni tags: trunk, main
10:22
Fix [4b22d84a] - const crash if undefined namespace check-in: 55c44ee180 user: apnadkarni tags: core-9-0-branch
02:33 • Ticket [4b22d84a62] Core Dump when setting const with non-existent namespace... artifact: 9a7d7d6e17 user: apnadkarni
2026-03-13
18:37 • Ticket [4b22d84a62]: 3 changes artifact: bf9a90f2ae user: stu
18:29 • Ticket [4b22d84a62]: 3 changes artifact: 29c26fc151 user: stu
18:28 • Ticket [4b22d84a62]: 3 changes artifact: 8c62b04a2d user: stu
18:03 • Ticket [4b22d84a62]: 3 changes artifact: 5fc794d186 user: apnadkarni
17:32 • Ticket [4b22d84a62]: 3 changes artifact: eec7e42271 user: stu
14:26 • Ticket [4b22d84a62]: 3 changes artifact: 9084d2dd80 user: apnadkarni
14:14
Bug [4b22d84a62]. const crash on non-existent namespace check-in: cfc42afaa0 user: apnadkarni tags: bug-4b22d84a62
11:36 • Ticket [4b22d84a62] Core Dump when setting const with non-existent namespace... artifact: 005255e918 user: stu
11:35 • Ticket [4b22d84a62]: 3 changes artifact: 8f5c1a9ca9 user: stu
2026-01-11
00:18 • New ticket [4b22d84a62]. artifact: 89e2e62adb user: sheckandar

Ticket UUID: 4b22d84a6236ed01b4ba300556dc4f4c78214ee0
Title: Core Dump when setting const with non-existent namespace
Type: Bug Created on: 2026-01-11 00:18:40
Submitter: sheckandar Assigned to: nobody
Subsystem: 07. Variables Severity: Important
Priority: 5 Medium Last modified: 2026-03-14 13:08:28
Status: Closed Closed by: stu
Resolution: Fixed Closed on: 2026-03-14 13:08:28
Version: 9.0.3
Description:

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.

User Comments:
stu added on 2026-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");

stu added on 2026-03-13 11:36:54:
There should be a test for this as well.

apnadkarni added on 2026-03-13 14:26:51:
Proposed fix in [ba4d418633].

stu added on 2026-03-13 17:32:53:
Not "goto constError;" or even "goto gotError;" ?

That seems to be the normal exit route.

apnadkarni added on 2026-03-13 18:03:19:
@stu, which line are you referring to? It does do "goto gotError".

stu added on 2026-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].

stu added on 2026-03-13 18:29:36:
Also, looks like the code in that file does:
if (!varPtr)
not:
if (varPtr == NULL)

stu added on 2026-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.

apnadkarni added on 2026-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.

stu added on 2026-03-14 13:08:28:
TclExecute.c has
4 "if (varPtr == NULL)"
8 "if (!varPtr)"

*not-too-impressed-shrug*