Context Generation from Formal Specifications for C Analysis Tools
Michele Alberti1 Julien Signoles2
1TrustInSoft 2CEA LIST, Software Reliability and Security Laboratory
LOPSTR 2017, Namur, Belgium
1
Context Generation from Formal Specifications for C Analysis Tools - - PowerPoint PPT Presentation
Context Generation from Formal Specifications for C Analysis Tools Michele Alberti 1 Julien Signoles 2 1 TrustInSoft 2 CEA LIST, Software Reliability and Security Laboratory LOPSTR 2017, Namur, Belgium 1 Code Analysis Tools Effective enough
1TrustInSoft 2CEA LIST, Software Reliability and Security Laboratory
1
2
int foo (int *a, size_t size) { /* some interesting computation */ }
3
int foo (int *a, size_t size) { /* some interesting computation */ }
3
int foo (int *a, size_t size) { /* some interesting computation */ }
3
4
4
4
5
6
7
/*@ requires \valid(a); @ requires 0 <= size <= 32; @ requires size % 16 == 0; @ ensures \forall integer i; 0 <= i < size ==> *(a+i) == 0; */ int foo (int *a, size_t size) { ... }
8
/*@ requires \valid(a); @ requires 0 <= size <= 32; @ requires size % 16 == 0; @ ensures \forall integer i; 0 <= i < size ==> *(a+i) == 0; */ int foo (int *a, size_t size) { ... }
8
9
10
/*@ requires defined(buf + (0..size-1)); @ requires 4 <= size <= 16; @ requires size % 2 == 0; @ requires *(buf + n) == 0xC0000001; */ int bar (int *buf, int size, int n)
11
/*@ requires defined(buf + (0..size-1)); @ requires 4 <= size <= 16; @ requires size % 2 == 0; @ requires *(buf + n) == 0xC0000001; */ int bar (int *buf, int size, int n)
int size; make_int(&size, 1); int* buf = (int*) malloc(size * sizeof(int)); make_int(buf, size); if (4 <= size) && (size <= 16) { ... }
11
/*@ requires defined(buf + (0..size-1)); @ requires 4 <= size <= 16; @ requires size % 2 == 0; @ requires *(buf + n) == 0xC0000001; */ int bar (int *buf, int size, int n)
int size; make_int(&size, 1); int* buf = (int*) malloc(size * sizeof(int)); make_int(buf, size); if (4 <= size) && (size <= 16) { ... }
11
/*@ requires defined(buf + (0..size-1)); @ requires 4 <= size <= 16; @ requires size % 2 == 0; @ requires *(buf + n) == 0xC0000001; */ int bar (int *buf, int size, int n)
int size, n; make_int(&size, 1); make_int(&n, 1); if (4 <= size) && (size <= 16) { if (size % 2 == 0) { int* buf = (int*) malloc(size * sizeof(int)); make_int(buf, size); *(buf + n) = 0xC0000001; bar(buf, size, n); } }
12
/*@ requires defined(buf + (0..size-1)); @ requires 4 <= size <= 16; @ requires size % 2 == 0; @ requires *(buf + n) == 0xC0000001; */ int bar (int *buf, int size, int n)
int size, n; make_int(&size, 1); make_int(&n, 1); if (4 <= size) && (size <= 16) { if (size % 2 == 0) { int* buf = (int*) malloc(size * sizeof(int)); make_int(buf, size); *(buf + n) = 0xC0000001; bar(buf, size, n); } }
12
13
/*@ requires defined(buf + (0..size-1)); // (1) @ requires 4 <= size <= 16; // (2) @ requires size % 2 == 0; // (3) @ requires *(buf + n) == 0xC0000001; // (4) */ int bar (int *buf, int size, int n)
13
/*@ requires defined(buf + (0..size-1)); // (1) @ requires 4 <= size <= 16; // (2) @ requires size % 2 == 0; // (3) @ requires *(buf + n) == 0xC0000001; // (4) */ int bar (int *buf, int size, int n)
13
/*@ requires defined(buf + (0..size-1)); // (1) @ requires 4 <= size <= 16; // (2) @ requires size % 2 == 0; // (3) @ requires *(buf + n) == 0xC0000001; // (4) */ int bar (int *buf, int size, int n)
13
/*@ requires defined(buf + (0..size-1)); // (1) @ requires 4 <= size <= 16; // (2) @ requires size % 2 == 0; // (3) @ requires *(buf + n) == 0xC0000001; // (4) */ int bar (int *buf, int size, int n)
13
/*@ requires defined(buf + (0..size-1)); // (1) @ requires 4 <= size <= 16; // (2) @ requires size % 2 == 0; // (3) @ requires *(buf + n) == 0xC0000001; // (4) */ int bar (int *buf, int size, int n)
14
15
15
16
17
i=1 Ci:
17
/*@ requires defined(buf + (0..size-1)); @ requires 4 <= size <= 16; @ requires size % 2 == 0; @ requires *(buf + n) == 0xC0000001; */ int bar (int *buf, int size, int n)
1
int bar_context (void){
2
int n;
3
Frama_C_make_unknown(&n, sizeof(int));
4
int size = Frama_C_int_interval(4, 16);
5
if (size % 2 == 0) {
6
int max = size > n ? size : n;
7
int* buf = (int*) malloc(max * sizeof(int));
8
if (buf != (int*) 0) {
9
Frama_C_make_unknown(buf, max * sizeof(int));
10
*(buf + n) = 0xC0000001;
11
bar(buf, size, n);
12
}
13
}
14
return 0;
15
}
18
19
20