Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 23ed8939840483bd7a2f4622759c73f4b0d9c1d2f26db1cdfaaef66168a4303a
Ticket: 992f94d847abfc48145f375561505932bf509604
avoid misaligned pointers in macOS file attribute functions
User & Date: chrstphrchvz on 2021-12-11 00:17:39
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    In <tt>TclMacOSXGetFileAttribute()</tt> and <tt>TclMacOSXSetFileAttribute()</tt> (macosx/tclMacOSXFCmd.c), <tt>fileinfobuf finfo</tt> only has 4-byte alignment. When <tt>finfo.data</tt> is not 8-byte aligned, casting <tt>&amp;finfo.data</tt> to <tt>(*off_t)</tt> is undefined behavior, and UBSan (<tt>-fsanitize=alignment</tt>) will complain when <tt>off_t *rsrcForkSize</tt> is dereferenced. Output for macOSXFCmd.test (with macOSXFCmd-2.7 reenabled, which I observe passes on APFS):
    
    <pre>
    $ ./tcltest ../tests/macOSXFCmd.test
    <span style="font-weight:bold">tcl/macosx/tclMacOSXFCmd.c:199:39: <span style="color:red">runtime error:</span> load of misaligned address 0x7ff7bf70a1d4 for type 'off_t' (aka 'long long'), which requires 8 byte alignment</span>
    <span style="font-weight:bold">0x7ff7bf70a1d4: note:</span> pointer points here
      0c 00 00 00 00 00 00 00  00 00 00 00 0f 00 00 00  10 6d fe 01 01 00 00 00  80 36 5b 00 00 60 00 00
                  <span style="color:green">^</span> 
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/macosx/tclMacOSXFCmd.c:199:39 in 
    <span style="font-weight:bold">tcl/macosx/tclMacOSXFCmd.c:327:25: <span style="color:red">runtime error:</span> load of misaligned address 0x7ff7bf70a0f4 for type 'off_t' (aka 'long long'), which requires 8 byte alignment</span>
    <span style="font-weight:bold">0x7ff7bf70a0f4: note:</span> pointer points here
      0c 00 00 00 03 00 00 00  00 00 00 00 00 60 00 00  00 42 ca 02 00 60 00 00  68 42 ca 02 00 60 00 00
                  <span style="color:green">^</span> 
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/macosx/tclMacOSXFCmd.c:327:25 in 
    macOSXFCmd.test:	Total	14	Passed	14	Skipped	0	Failed	0
    </pre>
    
    The attached patch uses <tt>memcpy()</tt> to avoid creating or dereferencing misaligned pointers, although there may be a better approach.
    
  5. foundin changed to: "8.6.12"
  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: "37. File System"
  14. title changed to:
    avoid misaligned pointers in macOS file attribute functions
    
  15. type changed to: "Patch"