Tcl_Merge(): out-of-bounds write, more signed integer overflow
- When argc is negative, there is signed integer overflow in the expression INT_MAX - argc + 1.
(Assuming 32-bit int.) If argc == INT_MIN, the current behavior is to allocate a 2GiB buffer and then write '\0' to the byte prior to the beginning of buffer. Otherwise, if INT_MIN < argc && argc < 0, then the function panics, claiming max size for a Tcl value (2147483647 bytes) exceeded.
At a minimum, I would suggest changing the behavior of the function slightly so that it always panics to prevent the out-of-bounds write; panicking is already possible in that case during the ckalloc(INT_MIN) call. Maybe a more helpful panic message can be used. See attached patch for a possible solution.
63b0443866Follow-up to [1599352cca]: Tcl_Merge(): out-of-bounds write, more signed integer overflow. Better panic message when argc < 0. check-in2022-10-07 10:18:330e2b23ff84Fix [e32a44e2e4], [1599352cca], [5ec43cfd9b] and [74cc95b563] check-in2022-10-06 09:06:07337d46bdb8Fix [1599352cca] and related issues check-in2022-10-05 15:31:31
Should be fixed [here]
[0e2b23ff845b] does fix quite a few issues, including some I had suspected or had not yet reported.
However there is still the issue of argc == INT_MAX leading to an out-of-bounds write. Is this won't-fix for Tcl < 9.0?
I meant argc == INT_MIN in the previous comment.
Should be better now: [63b0443866958521]
Attachments:
- 1599352cca83.diff [download] added by chrstphrchvz on 2022-10-02 14:06:20. [details]