Comments (3)
Tests of casts from function names with unchecked pointers to checked function pointer types were added as part of pull request #91. We still need to implement a check in the compiler that the source operand for the cast is actually a function name.
from checkedc-clang.
From an email from David:
The main motivation for the work is that C converts values with function types to pointers to function types. By default, these are unchecked pointers to function types. We need some way to create checked pointers to function types. Checked C allows implicit conversions from unchecked pointer types to checked pointer types, so we have a way of doing this in the extension already. However, Checked C relies on determining the actual bounds for the unchecked value. Of course, for function types, there is no bounds and no way to determine “the actual bounds”. We need some check to prevent implicit conversion of an unchecked function pointer value that does not match its declared “bounds” for arguments or the return value to a checked function pointer value. The check is to just to make sure that the actual source of the unchecked function pointer is a function name.
In other words, we want to prevent things like:
int bad_convert(int (*f)(int a)) { ptr<int (int)> safe_f = f; }
If the programmer wants to do that, we want to require an explicit (unsafe) cast, not have this conversion happen implicitly.
from checkedc-clang.
So, by staring at some dumped ASTs, we need to do the following:
- check any ImplicitCasts (specifically, Bitcasts)
- if they contain another implicitcast (specifically a function to pointer decay) and that contains a declref to a function, then we're all good. This is really the only kind of assignment that's allowed.
- otherwise, they likely contain an implicitcast (specifically a LValue to RValue cast) and that contains a DeclRef of a ParmVar (or similar, I'm not sure what the ref is like of a local variable), which is explicitly not allowed.
We'll pick this back up when we have a centralized place for doing our bounds checking analysis, which should be in a day or two.
from checkedc-clang.
Related Issues (20)
- Do not emit bounds checking warnings or errors for bounds-safe interfaces in certain contexts
- Consider emitting warnings for uses of pointers that violate their bounds-safe interfaces
- Allow `printf`-like calls in checked scopes if they pass `-Wformat` validation HOT 3
- Another crash while using checkedC HOT 2
- Move language conformance tests related to Where clauses to the checkedc repository
- Type-(un)safe unions (bug, and suggestion) ?
- Invertibility does not use semantic expression comparison
- Missing checks in calls to variadic functions inside checked scope HOT 1
- Missing checks in calls to variadic functions inside checked scope
- Equality should not be recorded between expressions such as x and x + 1 HOT 1
- "stdlib.h" not found in stdlib_checked.h HOT 3
- Fail to catch an out-of-bounds access at compile time
- Option to warn for each inserted runtime check that can't be proved unnecessary
- Eliminate null checks if the OS is known to trap failures safely
- No error on assignment to global variable used in bounds of another global variable (unsound) HOT 1
- Local variable bounds dependent on global variable can be invalidated by function call (unsound) HOT 1
- Maintain a complete, up-to-date list of unimplemented parts of the Checked C specification
- Checked-pointer local variable can be initialized with itself (unsound) HOT 1
- Compiler issues in Apple Silicon Systems HOT 1
- This repo is missing important files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from checkedc-clang.