-
Notifications
You must be signed in to change notification settings - Fork 1.2k
UBSan: Fix unaligned load/stores found by Undefined Behaviour Sanitizer. #2522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci test |
@swift-ci test macos |
@@ -501,7 +501,7 @@ static void _flattenPlist(CFPropertyListRef plist, CFMutableArrayRef objlist, CF | |||
CFDictionaryAddValue(objtable, plist, (const void *)(uintptr_t)refnum); | |||
if (_kCFRuntimeIDCFDictionary == type) { | |||
CFIndex count = CFDictionaryGetCount((CFDictionaryRef)plist); | |||
STACK_BUFFER_DECL(CFPropertyListRef, buffer, count <= 128 ? count * 2 : 1); | |||
STACK_BUFFER_DECL(CFPropertyListRef, buffer, (count > 0 && count <= 128) ? count * 2 : 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this same check need to be repeated on the next line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be needed because if count == 0
then the stack allocation is used instead of the malloc()
'd buffer. 1 byte is wasted on the stack but this is also the case if count > 128
and the heap is used instead of the stack.
#endif | ||
|
||
/* Read bytes until the buffer is aligned. */ | ||
while( ( (uintptr_t)bytes & align_mask ) && len > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nit; let's make it match the rest of the file
- Add unaligned_load32() / unaligned_store32() and unaligned_load{16,32,64}be() that load/store using byte access. On supported architectures clang should convert these into single load / store instructions. - When allocating buffers on the stack using STACK_BUFFER_DECL() ensure the length is > 0, as VLA (Variable Length Arrays) cannot be 0 length.
0230dbe
to
73daa3e
Compare
@swift-ci test |
1 similar comment
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me; I'd like to get a second pair of eyes on here (@millenomi perhaps).
@millenomi @phausler would you be able to have a look over this if you have some time? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me
@swift-ci test and merge |
Add unaligned_load32() / unaligned_store32() and
unaligned_load{16,32,64}be() that load/store using byte access. On
supported architectures clang should convert these into single
load / store instructions.
When allocating buffers on the stack using STACK_BUFFER_DECL() ensure
the length is > 0, as VLA (Variable Length Arrays) cannot be 0 length.