Skip to content
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

To keep ubsan happy, Use offsetof() rather than legacy equivalent #73657

Merged
merged 4 commits into from
Aug 11, 2022

Conversation

RobertHenry6bev
Copy link
Contributor

The existing code causes ubsan to generate a runtime error when using the &((Type *)0->field idiom.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Aug 9, 2022
// support for offsetof() on anything other than a standard-layout class
// is conditionally supported.
// This is more generous than the C++ standards when this code was originally written
//
// PAL_safe_offsetof is a version of offsetof that protects against an
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can delete this comment and PAL_safe_offsetof and replace all its occurences with just offsetof.

// overridden operator&
// overridden operator&. Note, however, C++-98 and newer
// requires offsetof to work correctly even if operator& is overloaded.
//

#define FIELD_OFFSET(type, field) __builtin_offsetof(type, field)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for FIELD_OFFSET. You can delete the definition and replace the few uses with offsetof.

Using offsetof() will prevent various static analyzers and dynamic ubsan
from complaining about indirecting through NULL.
@jkotas
Copy link
Member

jkotas commented Aug 11, 2022

The test failure is #73299

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jkotas jkotas merged commit 17154bd into dotnet:main Aug 11, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-PAL-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants