Overview
| Artifact ID: | e1add02fcd2b44254218558256b37a122398f2805f520a3bee79225f2562d956 |
|---|---|
| Ticket: | 8911644dc28094b08b47b20df766aeafc64ace7a
clock: use-after-free when a callback clears the clock caches, and memory errors on malformed locale data |
| User & Date: | bef on 2026-11-13 20:17:54 |
Changes
- icomment:
Fixes on branch [bug-891164-clock-memory-errors](/info/bug-891164-clock-memory-errors). Each fix is its own commit, so that it can be picked to other branches on its own; the commits do not depend on each other. The fixes are for 9.x only; 8.6 is not changed. Tests are in `tests/clock.test` (new groups `clock-81` and `clock-82`, to be renumbered as you like). **Item 1** (commit 01). References are taken for the duration of each command on the catalogue, the locale, the time zone, the client data and the format storage, and released in a new `ClockFreeFmtScnArgs`. The time zone is set through a new `ClockSetOptsTimezone`, also where `clock scan` changes it (`%Z`, and a zone in free-form input). Writes to a shared catalogue now go through a temporary smart reference (`TclClockMCDictPut`). The commit also fixes the `mcget` result used after `Tcl_ResetResult` and the leaked smart reference. One case is left: a callback that edits `::tcl::clock::mcMergedCat` in place can still change catalogue values that C holds by pointer. Tests `clock-82.1` to `clock-82.6`, each in a child interpreter. **Item 2** (commits 02, 03). Commit 02 builds the keys lowercased character by character with `Tcl_UniCharToLower`. Keys without U+023A or U+023E come out byte for byte as before. Test `clock-82.7` fails by result even without a sanitiser. Commit 03 resets `firstPtr` and `lastPtr` after freeing the items. No test, since the suite cannot make an allocation fail. **Item 3** (commit 04). NULL checks with the error "malformed locale data" (`CLOCK malformedLocaleData`, modelled on `malformedTimeZoneData`), and the `goto done` becomes `goto error`. The same error replaces the empty message for short `MONTHS_*`, `DAYS_OF_WEEK_*` and `LOCALE_NUMERALS` lists in `TclClockFormat`. The message and error code are only a suggestion. A quiet fallback (plain digits for a short `LOCALE_NUMERALS` list, an empty name as in 8.6) would also do. Tests `clock-81.1` to `clock-81.4`, `clock-81.8`, `clock-81.9`. **Test runs** The four commits on the branch (from trunk 12c60e9c42) were tested with ASan and UBSan, with UBSan's pointer-overflow check on: - `clock.test`: 8783 tests, 0 failed, no sanitiser report. - `clock-ivm.test`, `msgcat.test`, `safe.test` and `safe-stock.test`: no failures and no sanitiser reports. They were also run on a TCL_MEM_DEBUG build. `clock.test` passes there. Over 12000 rounds of `clock format`, `scan` and `add` in three locales, memory stays flat when the caches are cleared between rounds. Without clearing, it grows by exactly as much as unpatched trunk does over the same rounds, so the new references balance.
- login: "bef"
- mimetype: "text/x-markdown"