Artifacts Associated With Ticket 49538c09c8d7e93a
Ticket change [9125bbfa6e] (rid 257013) by serhiy.storchaka on 2026-09-25 17:27:46:
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
In <code>TclUnixWaitForFile()</code> (unix/tclUnixNotfy.c) <code>now</code> is only assigned if <code>timeout > 0</code>, but the loop is <pre> do { ... if (timeout < 0) { continue; } now = Tcl_GetDayTime(); } while (abortTime > now); </pre> <code>continue</code> in a do-while jumps to the condition, so with <code>timeout < 0</code> (wait forever), whenever <code>poll()</code> returns without a requested event (e.g. -1 with EINTR on a signal, or POLLNVAL), <code>abortTime > now</code> is evaluated with <code>abortTime == 0</code> and an uninitialized <code>now</code>. Depending on the garbage value the function either waits again or returns 0 ("not ready") although the wait was infinite. GCC reports it as "'now' may be used uninitialized" (seen with gcc 8.3 on DragonFly and gcc 10.5 on NetBSD), although at the first use at line 595, which is guarded by <code>timeout > 0</code>. <code>WaitForConnect()</code> in tclUnixSock.c calls it with -1 in a loop, which hides the early return there, but other callers (it is in the internal stubs table) are affected. 9.0 has the same loop (with <code>Tcl_Time</code>); 8.6 uses <code>while (1)</code> and is not affected. - foundin initialized to: "9.0.4, 9.1b1"
- login: "serhiy.storchaka"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "serhiy.storchaka"
- subsystem initialized to: "01. Notifier"
- title initialized to:
TclUnixWaitForFile: infinite wait reads uninitialized "now" and may return early
- type initialized to: "Bug"
Ticket change [86b7b3f0ef] (rid 257018) by serhiy.storchaka on 2026-09-25 17:39:09:
- icomment:
Proposed fix in [65772037dd] (branch unix-waitforfile-infinite-wait): use <code>while (1)</code> with an explicit timeout check, as in the macOS version. New test event-13.9 interrupts an infinite wait with <code>testalarm</code>; without the fix the wait returns early.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [19a391b05d] (rid 257900) by jan.nijtmans on 2026-10-13 12:25:48:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2461327.0179242012"
- closer changed to: "jan.nijtmans"
- comment changed to:
In <code>TclUnixWaitForFile()</code> (unix/tclUnixNotfy.c) <code>now</code> is only assigned if <code>timeout > 0</code>, but the loop is <pre> do { ... if (timeout < 0) { continue; } now = Tcl_GetDayTime(); } while (abortTime > now); </pre> <code>continue</code> in a do-while jumps to the condition, so with <code>timeout < 0</code> (wait forever), whenever <code>poll()</code> returns without a requested event (e.g. -1 with EINTR on a signal, or POLLNVAL), <code>abortTime > now</code> is evaluated with <code>abortTime == 0</code> and an uninitialized <code>now</code>. Depending on the garbage value the function either waits again or returns 0 ("not ready") although the wait was infinite. GCC reports it as "'now' may be used uninitialized" (seen with gcc 8.3 on DragonFly and gcc 10.5 on NetBSD), although at the first use at line 595, which is guarded by <code>timeout > 0</code>. <code>WaitForConnect()</code> in tclUnixSock.c calls it with -1 in a loop, which hides the early return there, but other callers (it is in the internal stubs table) are affected. 9.0 has the same loop (with <code>Tcl_Time</code>); 8.6 uses <code>while (1)</code> and is not affected. - icomment:
Fixed in [614f5eb377|trunk] and core-9-0-branch. Tcl 8.6 didn't have this bug. Many thanks!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"