Skip to content
Tcl Source Code View Ticket
Login

View Ticket

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.