Thrift
  1. Thrift
  2. THRIFT-1248

pointer subtraction in TMemoryBuffer relies on undefined behavior

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 0.5
    • Fix Version/s: 1.0
    • Component/s: C++ - Library
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      The ensureCanWrite function in TMemoryBuffer currently "rebases" the buffer pointers by subtracting the original buffer pointer from the pointer newly returned by realloc. While this seems to work fine on my linux setup(I couldn't force a reproducer), pointer subtraction between pointers that we allocated separately is an undefined operation.

      I have run into problems with this on platforms other than linux.

      I am attaching a patch that removes the undefined operation.

      1. 0_7_0_ptrdiff.patch
        1.0 kB
        Anatoly Fayngelerin

        Activity

        Hide
        Jens Geyer added a comment -

        Anatoly Fayngelerin,
        I see the point. Could you please

        • rebase the patch to current trunk
        • have a look whether wBound_ is really calculated correctly after your modifications being applied?

        Thank you!

        Show
        Jens Geyer added a comment - Anatoly Fayngelerin , I see the point. Could you please rebase the patch to current trunk have a look whether wBound_ is really calculated correctly after your modifications being applied? Thank you!
        Jens Geyer made changes -
        Patch Info Patch Available [ 10042 ]
        Jens Geyer made changes -
        Patch Info Patch Available [ 10042 ]
        Jake Farrell made changes -
        Fix Version/s 1.0 [ 12318851 ]
        Fix Version/s 0.9 [ 12316294 ]
        Jake Farrell made changes -
        Fix Version/s 0.9 [ 12316294 ]
        Fix Version/s 0.8 [ 12316293 ]
        Jake Farrell made changes -
        Fix Version/s 0.8 [ 12316293 ]
        Jake Farrell made changes -
        Fix Version/s 0.8 [ 12316293 ]
        Jake Farrell made changes -
        Fix Version/s 0.8 [ 12316293 ]
        Fix Version/s 0.7 [ 12315360 ]
        Anatoly Fayngelerin made changes -
        Field Original Value New Value
        Attachment 0_7_0_ptrdiff.patch [ 12488206 ]
        Anatoly Fayngelerin created issue -

          People

          • Assignee:
            Anatoly Fayngelerin
            Reporter:
            Anatoly Fayngelerin
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:

              Development