Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2022-02-17
09:30
Addendum to [7deeddb36]: Use WIDE_MIN/WIDE_MAX in more places check-in: de10721755 user: jan.nijtmans tags: core-8-6-branch
02:27 • Add attachment use-wide-macros.diff to ticket [7deeddb36f217dac|7deeddb... artifact: 9eb3d05c0a user: chrstphrchvz
02:26 • Ticket [7deeddb36f] signed integer overflow in Tcl_ScanObjCmd() status still... artifact: 7824bcad74 user: chrstphrchvz
2022-02-16
14:34 • Closed ticket [7deeddb36f]. artifact: 66a50f8b92 user: jan.nijtmans
14:33
Fix [7deeddb36]: signed integer overflow in Tcl_ScanObjCmd() check-in: 0ac2e76e3f user: jan.nijtmans tags: core-8-6-branch
08:57 • Add attachment scanobjcmd-widemin.diff to ticket [7deeddb36f217dac|7dee... artifact: 36c85fa3ae user: chrstphrchvz
08:57 • New ticket [7deeddb36f] signed integer overflow in Tcl_ScanObjCmd(). artifact: 6d48050bb8 user: chrstphrchvz

signed integer overflow in Tcl_ScanObjCmd()

Closed / Fixed7deeddb36f217dac87bc68cb69718a89e3c7d5d7Created 5 years agoUpdated 5 years ago
Descriptionwiki2022-02-16 08:57:16
Setting Tcl_WideInt wideValue to the highest value representable by Tcl_WideInt and then doing wideValue++ is signed integer overflow (undefined behavior).

UBSan (-fsanitize=signed-integer-overflow) error when Tcl_WideInt is long long:

% scan -0x18000000000000000 {%li}
tcl/generic/tclScan.c:926:13: runtime error: signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long long int'
-9223372036854775808

Likewise when Tcl_WideInt is long:

% scan -0x18000000000000000 {%li}
tcl/generic/tclScan.c:926:13: runtime error: signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'Tcl_WideInt' (aka 'long')
-9223372036854775808

Increment only after casting to Tcl_WideUInt if wraparound behavior is desired (without e.g. -fwrapv); see attached patch.

jan.nijtmanswiki2022-02-16 14:34:58

Fixed [here]

Thanks for the report!

chrstphrchvzwiki2022-02-17 02:26:48

I now notice the WIDE_MIN and WIDE_MAX macros in tclPort.h; should those be used instead for consistency? See use-wide-macros.diff.

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