-
Notifications
You must be signed in to change notification settings - Fork 277
Restrict function pointers by name #5262
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
Merged
danpoe
merged 7 commits into
diffblue:develop
from
danpoe:feature/restrict-function-pointer-by-name
Mar 24, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d3f9fe7
Add restrict-function-pointer-by-name option
hannes-steffenhagen-diffblue 19040a4
Pass command line option to parse_function_pointer_restriction()
danpoe 84054d5
Refactorings and cleanups for the restrict function pointer by name f…
danpoe 0e659f9
Update restrict function pointer by name regression tests
danpoe 0744710
Add unit tests for the restrict function pointers by name feature
danpoe 9917b20
Refactor get_by_name_restriction()
danpoe 8154f23
Refactor error handling of function pointer restriction
danpoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
regression/goto-instrument/restrict-function-pointer-by-name-global/test.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
int f(void) | ||
{ | ||
return 1; | ||
} | ||
|
||
int g(void) | ||
{ | ||
return 2; | ||
} | ||
|
||
int h(void) | ||
{ | ||
return 3; | ||
} | ||
|
||
typedef int (*fp_t)(void); | ||
|
||
fp_t fp; | ||
|
||
void main() | ||
{ | ||
int cond; | ||
fp = cond ? f : g; | ||
int res = fp(); | ||
__CPROVER_assert(res == 1, ""); | ||
__CPROVER_assert(res == 2, ""); | ||
__CPROVER_assert(res == 1 || res == 2, ""); | ||
} |
15 changes: 15 additions & 0 deletions
15
regression/goto-instrument/restrict-function-pointer-by-name-global/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CORE | ||
test.c | ||
--restrict-function-pointer-by-name fp/f,g | ||
\[main\.assertion\.1\] line \d+ dereferenced function pointer at main\.function_pointer_call\.1 must be one of \[(f, g)|(g, f)\]: SUCCESS | ||
\[main.assertion.2\] line \d+ assertion: FAILURE | ||
\[main.assertion.3\] line \d+ assertion: FAILURE | ||
\[main.assertion.4\] line \d+ assertion: SUCCESS | ||
f\(\) | ||
g\(\) | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
h\(\) | ||
-- | ||
Check that a call to a global function pointer is correctly restricted |
19 changes: 19 additions & 0 deletions
19
regression/goto-instrument/restrict-function-pointer-by-name-local/test.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <assert.h> | ||
|
||
int f(void) | ||
{ | ||
return 1; | ||
} | ||
|
||
int g(void) | ||
{ | ||
return 2; | ||
} | ||
|
||
typedef int (*fp_t)(void); | ||
|
||
void main() | ||
{ | ||
fp_t fp = f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐑 |
||
assert(fp() == 1); | ||
} |
12 changes: 12 additions & 0 deletions
12
regression/goto-instrument/restrict-function-pointer-by-name-local/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
test.c | ||
--restrict-function-pointer-by-name main::1::fp/f | ||
\[main\.assertion\.1\] line \d+ dereferenced function pointer at main\.function_pointer_call\.1 must be f: SUCCESS | ||
\[main\.assertion\.2\] line \d+ assertion fp\(\) == 1: SUCCESS | ||
f\(\) | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
g\(\) | ||
-- | ||
thk123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Check that a call to a local function pointer is correctly restricted |
23 changes: 23 additions & 0 deletions
23
regression/goto-instrument/restrict-function-pointer-by-name-parameter/test.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <assert.h> | ||
|
||
int f(void) | ||
{ | ||
return 1; | ||
} | ||
|
||
int g(void) | ||
{ | ||
return 2; | ||
} | ||
|
||
typedef int (*fp_t)(void); | ||
|
||
void use_fp(fp_t fp) | ||
{ | ||
assert(fp() == 1); | ||
} | ||
|
||
void main() | ||
{ | ||
use_fp(f); | ||
} |
12 changes: 12 additions & 0 deletions
12
regression/goto-instrument/restrict-function-pointer-by-name-parameter/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CORE | ||
test.c | ||
--restrict-function-pointer-by-name use_fp::fp/f | ||
\[use_fp\.assertion\.1\] line \d+ dereferenced function pointer at use_fp\.function_pointer_call\.1 must be f: SUCCESS | ||
\[use_fp\.assertion\.2\] line \d+ assertion fp\(\) == 1: SUCCESS | ||
f\(\) | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
g\(\) | ||
-- | ||
Check that a call to a function pointer parameter is correctly restricted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,30 +2,14 @@ | |
|
||
typedef int (*fptr_t)(int); | ||
|
||
fptr_t get_f(void); | ||
|
||
void use_f(fptr_t fptr) | ||
{ | ||
assert(fptr(10) >= 10); | ||
} | ||
|
||
void select_f(void); | ||
void select_g(void); | ||
void select_h(void); | ||
|
||
int main(void) | ||
{ | ||
select_f(); | ||
use_f(get_f()); | ||
select_g(); | ||
use_f(get_f()); | ||
select_h(); | ||
use_f(get_f()); | ||
fptr(1); | ||
} | ||
|
||
int f(int x) | ||
{ | ||
return x + 1; | ||
return x; | ||
} | ||
|
||
int g(int x) | ||
|
@@ -35,38 +19,19 @@ int g(int x) | |
|
||
int h(int x) | ||
{ | ||
return x - 1; | ||
} | ||
|
||
int select_function = 0; | ||
|
||
void select_f(void) | ||
{ | ||
select_function = 0; | ||
return x; | ||
} | ||
|
||
void select_g(void) | ||
int other(int x) | ||
{ | ||
select_function = 1; | ||
return x; | ||
} | ||
|
||
void select_h(void) | ||
int main(void) | ||
{ | ||
select_function = 2; | ||
use_f(f); | ||
use_f(g); | ||
use_f(h); | ||
use_f(other); | ||
} | ||
|
||
fptr_t get_f(void) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess all this deletion would be clearer if put in its own commit explaining why |
||
{ | ||
if(select_function == 0) | ||
{ | ||
return f; | ||
} | ||
else if(select_function == 1) | ||
{ | ||
return g; | ||
} | ||
else | ||
{ | ||
return h; | ||
} | ||
} |
7 changes: 4 additions & 3 deletions
7
...strict-function-pointer-to-multiple-functions-via-file-and-command-line-options/test.desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.