Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2023-03-22
17:13
Merge trunk 5c6fa768fe: Merge 8.6: Bug [183a1adcc0]. Buffer overflow in Tcl_UtfToExternal. check-in: 904fc79e30 user: pooryorick tags: unchained
2023-03-13
16:10 • Closed ticket [183a1adcc0]: Buffer overflow in Tcl_UtfToExternal plus 5 othe... artifact: 58120f69c3 user: apnadkarni
16:10 • Ticket [183a1adcc0]: 3 changes artifact: 3b495b1ef2 user: apnadkarni
15:59
Merge 8.7: Bug [183a1adcc0]. Buffer overflow in Tcl_UtfToExternal check-in: 5c6fa768fe user: apnadkarni tags: trunk, main
15:34
Merge 8.6: Bug [183a1adcc0]. Buffer overflow in Tcl_UtfToExternal check-in: 24f607b329 user: apnadkarni tags: core-8-branch
13:44
Bug [183a1adcc0]. Buffer overflow in Tcl_UtfToExternal check-in: 4785751542 user: apnadkarni tags: core-8-6-branch
2023-03-12
17:33 • Ticket [183a1adcc0] Buffer overflow in Tcl_UtfToExternal status still Open w... artifact: f350212ca3 user: apnadkarni
17:05 • New ticket [183a1adcc0]. artifact: debaa2f082 user: apnadkarni

Buffer overflow in Tcl_UtfToExternal

Closed / Fixed183a1adcc07cddc6b55d0fc636c392ea461f1cccCreated 4 years agoUpdated 4 years ago
Descriptionmarkdown2023-03-12 17:05:18

When passed a one byte buffer, Tcl_UtfToExternal writes the null terminator beyond the buffer. In the TIP-656 branch,

% testencoding Tcl_UtfToExternal unicode A {start end} {} 1
Tcl_ExternalToUtf wrote past output buffer

The function is identical to the core-8-branch so the bug should appear there as well. 8.6 has slightly different code but has same issue.

Basically, the encoding's nul length is subtracted from the passed destination buffer length without checking for a negative result. Subsequently the nul bytes (2 in this case) are written to the buffer.

Although a single byte buffer might seem unlikely, the possibility exists in streaming operation where caller might repeatedly call the function using the same (updated) buffer until TCL_CONVERT_NOSPACE is returned and there happens to be just one free byte in the buffer.

Referenced by4
apnadkarni Ticket [183a1adcc0]: 3 changes [History diff]2023-03-12 17:33:15
apnadkarniplain2023-03-13 16:10:11
Fixed in [4785751542] for 8.6. Merged to 8.7 and 9.0
apnadkarni Closed ticket [183a1adcc0]. [History diff]2023-03-13 16:10:28
Log in (anonymous is fine) to add a comment.