possible signed integer overflow in Tcl_GetLongFromObj(), Tcl_GetWideIntFromObj()
Closed / Fixedc6fea6ba6f6b2841ad4d1a569ccc3cb6f6484abcCreated 5 years agoUpdated 5 years ago
Descriptionwiki2022-02-16 02:15:18
If Tcl_GetLongFromObj() or Tcl_GetWideIntFromObj() retrieve from a bignum whose value is LONG_MIN or WIDE_MIN respectively, then I believe there will be signed integer overflow (undefined behavior) on 2's complement systems.
The attached patch should avoid this by using the same approach suggested for [89de498973]: negate before casting, and by subtracting from 0 (binary minus) to avoid compiler warnings for unary minus with unsigned operand (e.g. MSVC /W2 warning C4146). However I have not identified a Tcl syntax example to trigger the overflow, as I have not found how to create a bignum with a value representable by long or Tcl_WideInt that can be saved and used by a command that then passes it to Tcl_GetLongFromObj() or Tcl_GetWideIntFromObj(); maybe I can come up with a C example.
jan.nijtmanswiki2022-02-16 15:42:55
Fixed[here]
Thanks for the report!
Log in (anonymous is fine) to add a comment.