Overview
| Artifact ID: | 9125bbfa6eef2d0b47ac85882e693d425f5e1258644add1952b636a3db9c07a6 |
|---|---|
| Ticket: | 49538c09c8d7e93ab4375a41023c6c293f01cb5e
TclUnixWaitForFile: infinite wait reads uninitialized "now" and may return early |
| User & Date: | serhiy.storchaka on 2026-09-25 17:27:46 |
Changes
- cmimetype changed to: "text/x-fossil-wiki"
- 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. - foundin changed to: "9.0.4, 9.1b1"
- login: "serhiy.storchaka"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "serhiy.storchaka"
- subsystem changed to: "01. Notifier"
- title changed to:
TclUnixWaitForFile: infinite wait reads uninitialized "now" and may return early
- type changed to: "Bug"