Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2022-10-07
11:20 • Ticket [1599352cca] Tcl_Merge(): out-of-bounds write, more signed integer overfl... artifact: 19856075b2 user: jan.nijtmans
10:18
Follow-up to [1599352cca]: Tcl_Merge(): out-of-bounds write, more signed integer overflow. Better pa... check-in: 63b0443866 user: jan.nijtmans tags: core-8-6-branch
2022-10-06
20:17 • Ticket [1599352cca] Tcl_Merge(): out-of-bounds write, more signed integer overfl... artifact: e7689f573f user: chrstphrchvz
20:06 • Ticket [1599352cca]: 5 changes artifact: 6fd5b1699d user: chrstphrchvz
10:23 • Closed ticket [1599352cca]. artifact: 9dfc7dd265 user: jan.nijtmans
09:06
Fix [e32a44e2e4], [1599352cca], [5ec43cfd9b] and [74cc95b563] check-in: 0e2b23ff84 user: jan.nijtmans tags: core-8-6-branch
2022-10-05
15:31
Fix [1599352cca] and related issues closed check-in: 337d46bdb8 user: jan.nijtmans tags: bug-1599352cca
2022-10-02
14:06 • Add attachment 1599352cca83.diff to ticket [1599352cca83527b|1599352cca... artifact: baf3c5a6bb user: chrstphrchvz
14:04 • New ticket [1599352cca] Tcl_Merge(): out-of-bounds write, more signed integer ov... artifact: f65dc39c7e user: chrstphrchvz

Tcl_Merge(): out-of-bounds write, more signed integer overflow

Closed / Fixed1599352cca83527b22000b9e6a336fa84344bf61Created 4 years agoUpdated 4 years ago
Descriptionwiki2022-10-02 14:04:32
Although it only makes sense to provide nonnegative argc to Tcl_Merge(), the function is a public API currently making no effort to guard against negative argc.
  • 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.

Referenced by3
jan.nijtmanswiki2022-10-06 10:23:08

Should be fixed [here]

chrstphrchvzwiki2022-10-06 20:06:36

[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?

chrstphrchvzwiki2022-10-06 20:17:44

I meant argc == INT_MIN in the previous comment.

jan.nijtmanswiki2022-10-07 11:20:03

Should be better now: [63b0443866958521]

Log in (anonymous is fine) to add a comment.

Attachments: