Tcl Source Code

View Ticket
Login
Ticket UUID: abd489a1cf4782f0255f307c42370d3a5e27c464
Title: TclStringCmp() calls functions through pointer to incorrect type
Type: Patch Created on: 2023-10-13 07:20:01
Submitter: chrstphrchvz Assigned to: jan.nijtmans
Subsystem: 18. Commands M-Z Severity: Minor
Priority: 5 Medium Last modified: 2023-12-30 00:20:14
Status: Closed Closed by: jan.nijtmans
Resolution: Fixed Closed on: 2023-12-30 00:20:14
Version: 8.6.13
Description:

Example UBSan -fsanitize=function error:

% string compare a b
tcl/generic/tclCmdMZ.c:2863:10: runtime error: call to function TclpUtfNcmp2 through pointer to incorrect function type 'int (*)(const void *, const void *, unsigned long)'
tclUtf.c:1233: note: TclpUtfNcmp2 defined here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/generic/tclCmdMZ.c:2863:10 in 
-1

Some of the compare functions are public APIs, so I would suggest either using an enum to call functions directly, or wrapper functions (as done by the attached patch).

User Comments:
jan.nijtmans added on 2023-10-13 14:09:39:

Thanks for the patch! Looks good.

In this case, it's slightly better to do the wrapping slightly different: [6d9d5ac6a75d7832].


jan.nijtmans added on 2023-12-30 00:20:14:

This should be fixed in all branches now


Attachments: