Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

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

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. 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.
    
  5. foundin changed to: "core-8-6-branch"
  6. is_private changed to: "0"
  7. login: "chrstphrchvz"
  8. priority changed to: "5 Medium"
  9. resolution changed to: "None"
  10. severity changed to: "Minor"
  11. status changed to: "Open"
  12. submitter changed to: "chrstphrchvz"
  13. subsystem changed to: "48. Number Handling"
  14. title changed to:
    possible signed integer overflow in Tcl_GetLongFromObj(), Tcl_GetWideIntFromObj()
    
  15. type changed to: "Patch"