File tree Expand file tree Collapse file tree 10 files changed +123
-102
lines changed
regression/goto-instrument
restrict-function-pointer-by-name
restrict-function-pointer-by-name-global
restrict-function-pointer-by-name-local
restrict-function-pointer-by-name-parameter
restrict-function-pointer-to-multiple-functions-via-file-and-command-line-options Expand file tree Collapse file tree 10 files changed +123
-102
lines changed Original file line number Diff line number Diff line change
1
+ int f (void )
2
+ {
3
+ return 1 ;
4
+ }
5
+
6
+ int g (void )
7
+ {
8
+ return 2 ;
9
+ }
10
+
11
+ int h (void )
12
+ {
13
+ return 3 ;
14
+ }
15
+
16
+ typedef int (* fp_t )(void );
17
+
18
+ fp_t fp ;
19
+
20
+ void main ()
21
+ {
22
+ int cond ;
23
+ fp = cond ? f : g ;
24
+ int res = fp ();
25
+ __CPROVER_assert (res == 1 , "" );
26
+ __CPROVER_assert (res == 2 , "" );
27
+ __CPROVER_assert (res == 1 || res == 2 , "" );
28
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ test.c
3
+ --restrict-function-pointer-by-name fp/f,g
4
+ \[main\.assertion\.1\] line \d+ dereferenced function pointer at main\.function_pointer_call\.1 must be one of \[(g, f)|(g, f)\]: SUCCESS
5
+ \[main.assertion.2\] line \d+ assertion: FAILURE
6
+ \[main.assertion.3\] line \d+ assertion: FAILURE
7
+ \[main.assertion.4\] line \d+ assertion: SUCCESS
8
+ f\(\)
9
+ g\(\)
10
+ ^EXIT=10$
11
+ ^SIGNAL=0$
12
+ --
13
+ h\(\)
14
+ --
15
+ Check that a call to a global function pointer is correctly restricted
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ int f (void )
4
+ {
5
+ return 1 ;
6
+ }
7
+
8
+ int g (void )
9
+ {
10
+ return 2 ;
11
+ }
12
+
13
+ typedef int (* fp_t )(void );
14
+
15
+ void main ()
16
+ {
17
+ fp_t fp = f ;
18
+ assert (fp () == 1 );
19
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ test.c
3
+ --restrict-function-pointer-by-name main::1::fp/f
4
+ \[main\.assertion\.1\] line \d+ dereferenced function pointer at main\.function_pointer_call\.1 must be f: SUCCESS
5
+ \[main\.assertion\.2\] line \d+ assertion fp\(\) == 1: SUCCESS
6
+ f\(\)
7
+ ^EXIT=0$
8
+ ^SIGNAL=0$
9
+ --
10
+ g\(\)
11
+ --
12
+ Check that a call to a local function pointer is correctly restricted
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ int f (void )
4
+ {
5
+ return 1 ;
6
+ }
7
+
8
+ int g (void )
9
+ {
10
+ return 2 ;
11
+ }
12
+
13
+ typedef int (* fp_t )(void );
14
+
15
+ void use_fp (fp_t fp )
16
+ {
17
+ assert (fp () == 1 );
18
+ }
19
+
20
+ void main ()
21
+ {
22
+ use_fp (f );
23
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ test.c
3
+ --restrict-function-pointer-by-name use_fp::fp/f
4
+ \[use_fp\.assertion\.1\] line \d+ dereferenced function pointer at use_fp\.function_pointer_call\.1 must be f: SUCCESS
5
+ \[use_fp\.assertion\.2\] line \d+ assertion fp\(\) == 1: SUCCESS
6
+ f\(\)
7
+ ^EXIT=0$
8
+ ^SIGNAL=0$
9
+ --
10
+ g\(\)
11
+ --
12
+ Check that a call to a function pointer parameter is correctly restricted
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 2
2
3
3
typedef int (* fptr_t )(int );
4
4
5
- fptr_t get_f (void );
6
-
7
5
void use_f (fptr_t fptr )
8
6
{
9
- assert (fptr (10 ) >= 10 );
10
- }
11
-
12
- void select_f (void );
13
- void select_g (void );
14
- void select_h (void );
15
-
16
- int main (void )
17
- {
18
- select_f ();
19
- use_f (get_f ());
20
- select_g ();
21
- use_f (get_f ());
22
- select_h ();
23
- use_f (get_f ());
7
+ fptr (1 );
24
8
}
25
9
26
10
int f (int x )
27
11
{
28
- return x + 1 ;
12
+ return x ;
29
13
}
30
14
31
15
int g (int x )
@@ -35,38 +19,19 @@ int g(int x)
35
19
36
20
int h (int x )
37
21
{
38
- return x - 1 ;
39
- }
40
-
41
- int select_function = 0 ;
42
-
43
- void select_f (void )
44
- {
45
- select_function = 0 ;
22
+ return x ;
46
23
}
47
24
48
- void select_g ( void )
25
+ int other ( int x )
49
26
{
50
- select_function = 1 ;
27
+ return x ;
51
28
}
52
29
53
- void select_h (void )
30
+ int main (void )
54
31
{
55
- select_function = 2 ;
32
+ use_f (f );
33
+ use_f (g );
34
+ use_f (h );
35
+ use_f (other );
56
36
}
57
37
58
- fptr_t get_f (void )
59
- {
60
- if (select_function == 0 )
61
- {
62
- return f ;
63
- }
64
- else if (select_function == 1 )
65
- {
66
- return g ;
67
- }
68
- else
69
- {
70
- return h ;
71
- }
72
- }
Original file line number Diff line number Diff line change 1
1
CORE
2
2
test.c
3
- --function-pointer-restrictions-file restrictions.json --restrict-function-pointer use_f.function_pointer_call.1/g
4
- \[use_f\.assertion\.1\] line \d+ dereferenced function pointer at use_f.function_pointer_call.1 must be one of \[(f|g), (f|g)\]: FAILURE
3
+ --function-pointer-restrictions-file restrictions.json --restrict-function-pointer use_f.function_pointer_call.1/g --restrict-function-pointer-by-name use_f::fptr/h
4
+ \[use_f\.assertion\.1\] line \d+ dereferenced function pointer at use_f.function_pointer_call.1 must be one of \[(f|g|h ), (f|g|h), (f|g|h )\]: FAILURE
5
5
^EXIT=10$
6
6
^SIGNAL=0$
7
7
--
8
8
--
9
9
This test checks that the restrictions for a function pointer are the union of
10
- the restrictions given in a file and on the command line.
10
+ the restrictions given in a file and on the command line (both with functions
11
+ pointers being numbered and named)
11
12
12
13
The test further checks that the correct safety assertions are generated. The
13
14
function pointer restriction feature outputs safety assertions for all calls
You can’t perform that action at this time.
0 commit comments