Overview
| Artifact ID: | c30181b5087e19c4320e8a71492454418f6cbac08e3c113479cbca2d71e8d12e |
|---|---|
| Ticket: | bdd1b346f89df079ce13dfb3be5c80a6608cb282
Heap buffer overflow in `clock format` from a data race on the shared `fmtMinAlloc` |
| User & Date: | bef on 2026-11-09 08:30:25 |
Changes
- icomment:
Thanks for the two commits, both look right. The original patch only removed the double read that leads to the overflow, since the remaining accesses only affect the size hint. Taking `ClockFmtMutex` makes them race-free as well. A related pattern, not covered by this ticket: `ClockGetOrParseFmtFormat` tests `fss->fmtTok` without the mutex (`tclClockFmt.c:3253` on the branch) and returns the storage as soon as it is non-NULL, while the token array is filled under the mutex and published with a plain store at `:3377`. Nothing orders the stores into the array before the store of the pointer, so on a weakly ordered CPU (arm64, for example) a thread that formats with the same format string while another thread is still tokenising it can see the new pointer before the tokens behind it. `TclClockFormat` then walks the array until `tok->map == NULL` and calls through `map`. The scan side has the same shape (`ClockGetOrParseScanFormat`, `scnTok` at `:2164` and `:2346`). This has not been reproduced; it follows from the code, and the source comment at `:3376` ("note the threaded race condition") suggests it is known. The simplest fix is probably to drop the unlocked fast path and test `fmtTok` and `scnTok` only under the mutex, at the cost of one more uncontended lock per `clock format` and `clock scan`. - login: "bef"
- mimetype: "text/x-markdown"