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

Disallow casts between incompatible checked pointer types in checked scopes? #1114

Open
mattmccutchen-cci opened this issue Jul 1, 2021 · 0 comments
Labels
bug This labels issues that are bugs. priority:3 This labels bugs that are not very critical but still need to be addressed.

Comments

@mattmccutchen-cci
Copy link
Member

Something for your future consideration (not urgent):

The ability to cast between incompatible types containing checked pointers, even in a checked scope, is probably the most obvious remaining soundness hole in Checked C. An example (just to make it completely clear what I mean):

#pragma CHECKED_SCOPE on

int main(void) {
  long l = 12345;
  _Ptr<long> pl = &l;
  _Ptr<_Ptr<long>> ppl = (_Ptr<_Ptr<long>>)pl;
  **ppl = 67890;  // SEGV
  return 0;
}

Now that we have a distinction between _Checked and _Checked _Bounds_only scopes and are pursuing full type safety for the former, I think it probably makes sense to just disallow these casts in _Checked scopes. It seems reasonable to require the programmer to put an _Unchecked block around the cast, just as they have to do for many other kinds of unsafe operations.

Of course, this would break existing Checked C code, so we'd have to think about how to manage the compatibility problems. Maybe it's time to introduce a concept of Checked C "language standard" versions, analogous to the existing -std option for C language standard versions, so that users can enable stricter checking when they are ready to update their code.

@sulekhark sulekhark added bug This labels issues that are bugs. priority:3 This labels bugs that are not very critical but still need to be addressed. labels Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This labels issues that are bugs. priority:3 This labels bugs that are not very critical but still need to be addressed.
Projects
None yet
Development

No branches or pull requests

2 participants