Overview
| Artifact ID: | 6fec51f58c6c9be1908e92ddab069988154713ba1c79e3ac0d18ae57e79f8d11 |
|---|---|
| Ticket: | c6fea6ba6f6b2841ad4d1a569ccc3cb6f6484abc
possible signed integer overflow in Tcl_GetLongFromObj(), Tcl_GetWideIntFromObj() |
| User & Date: | chrstphrchvz on 2022-02-16 02:15:18 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
If <tt>Tcl_GetLongFromObj()</tt> or <tt>Tcl_GetWideIntFromObj()</tt> retrieve from a bignum whose value is <tt>LONG_MIN</tt> or <tt>WIDE_MIN</tt> 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. [https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4146|MSVC <tt>/W2</tt> 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 <tt>long</tt> or <tt>Tcl_WideInt</tt> 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.
- foundin changed to: "core-8-6-branch"
- is_private changed to: "0"
- login: "chrstphrchvz"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "chrstphrchvz"
- subsystem changed to: "48. Number Handling"
- title changed to:
possible signed integer overflow in Tcl_GetLongFromObj(), Tcl_GetWideIntFromObj()
- type changed to: "Patch"