Ticket UUID: | 992f94d847abfc48145f375561505932bf509604 | |||
Title: | avoid misaligned pointers in macOS file attribute functions | |||
Type: | Patch | Version: | 8.6.12 | |
Submitter: | chrstphrchvz | Created on: | 2021-12-11 00:17:39 | |
Subsystem: | 37. File System | Assigned To: | nobody | |
Priority: | 5 Medium | Severity: | Minor | |
Status: | Open | Last Modified: | 2022-02-16 23:17:24 | |
Resolution: | None | Closed By: | nobody | |
Closed on: | ||||
Description: |
In TclMacOSXGetFileAttribute() and TclMacOSXSetFileAttribute() (macosx/tclMacOSXFCmd.c), fileinfobuf finfo only has 4-byte alignment. When finfo.data is not 8-byte aligned, casting &finfo.data to (*off_t) is undefined behavior, and UBSan (-fsanitize=alignment) will complain when off_t *rsrcForkSize is dereferenced. Output for macOSXFCmd.test (with macOSXFCmd-2.7 reenabled, which I observe passes on APFS): $ ./tcltest ../tests/macOSXFCmd.test tcl/macosx/tclMacOSXFCmd.c:199:39: runtime error: load of misaligned address 0x7ff7bf70a1d4 for type 'off_t' (aka 'long long'), which requires 8 byte alignment 0x7ff7bf70a1d4: note: 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 ^ SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/macosx/tclMacOSXFCmd.c:199:39 in tcl/macosx/tclMacOSXFCmd.c:327:25: runtime error: load of misaligned address 0x7ff7bf70a0f4 for type 'off_t' (aka 'long long'), which requires 8 byte alignment 0x7ff7bf70a0f4: note: 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 ^ SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/macosx/tclMacOSXFCmd.c:327:25 in macOSXFCmd.test: Total 14 Passed 14 Skipped 0 Failed 0 The attached patch uses memcpy() to avoid creating or dereferencing misaligned pointers, although there may be a better approach. |
Attachments:
- 992f94d847.diff [download] added by chrstphrchvz on 2021-12-11 00:21:32. [details]