Skip to content

Commit 6e47d5a

Browse files
committed
C library: model currently supported behaviour of longjmp
We require (yet to be built) instrumentation to handle longjmp (and its variants). Therefore: 1) The only possible return value of `setjmp` (and its variants) is 0 for it can never be reached via longjmp (or its variants). 2) Fail an assertion when invoking longjmp to ensure we do not produce unsound verification results when longjmp is reachable on some path. Enable all related regression tests.
1 parent 3552cfb commit 6e47d5a

File tree

11 files changed

+128
-28
lines changed

11 files changed

+128
-28
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include <assert.h>
21
#include <setjmp.h>
32

3+
static jmp_buf env;
4+
45
int main()
56
{
6-
_longjmp();
7-
assert(0);
7+
_longjmp(env, 1);
8+
__CPROVER_assert(0, "unreachable");
89
return 0;
910
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check --bounds-check
4-
^EXIT=0$
4+
^\[_longjmp.assertion.1\] line 12 _longjmp requires instrumentation: FAILURE$
5+
^\[main.assertion.1\] line 8 unreachable: SUCCESS$
6+
^VERIFICATION FAILED$
7+
^EXIT=10$
58
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
79
--
810
^warning: ignoring
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include <assert.h>
21
#include <setjmp.h>
32

3+
static jmp_buf env;
4+
45
int main()
56
{
6-
longjmp();
7-
assert(0);
7+
longjmp(env, 1);
8+
__CPROVER_assert(0, "unreachable");
89
return 0;
910
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check --bounds-check
4-
^EXIT=0$
4+
^\[longjmp.assertion.1\] line 12 longjmp requires instrumentation: FAILURE$
5+
^\[main.assertion.1\] line 8 unreachable: SUCCESS$
6+
^VERIFICATION FAILED$
7+
^EXIT=10$
58
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
79
--
810
^warning: ignoring
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
#include <assert.h>
21
#include <setjmp.h>
32

3+
static jmp_buf env;
4+
45
int main()
56
{
6-
setjmp();
7-
assert(0);
7+
if(setjmp(env))
8+
__CPROVER_assert(0, "reached via longjmp");
9+
else
10+
__CPROVER_assert(0, "setjmp called directly");
811
return 0;
912
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check --bounds-check
4-
^EXIT=0$
4+
^\[main.assertion.1\] line 8 reached via longjmp: SUCCESS$
5+
^\[main.assertion.2\] line 10 setjmp called directly: FAILURE$
6+
^VERIFICATION FAILED$
7+
^EXIT=10$
58
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
79
--
810
^warning: ignoring
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include <assert.h>
21
#include <setjmp.h>
32

3+
static sigjmp_buf env;
4+
45
int main()
56
{
6-
siglongjmp();
7-
assert(0);
7+
siglongjmp(env, 1);
8+
__CPROVER_assert(0, "unreachable");
89
return 0;
910
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
KNOWNBUG
1+
CORE unix
22
main.c
33
--pointer-check --bounds-check
4-
^EXIT=0$
4+
^\[siglongjmp.assertion.1\] line 14 siglongjmp requires instrumentation: FAILURE$
5+
^\[main.assertion.1\] line 8 unreachable: SUCCESS$
6+
^VERIFICATION FAILED$
7+
^EXIT=10$
58
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
79
--
810
^warning: ignoring
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <setjmp.h>
2+
3+
static sigjmp_buf env;
4+
5+
int main()
6+
{
7+
if(sigsetjmp(env, 0))
8+
__CPROVER_assert(0, "reached via siglongjmp");
9+
else
10+
__CPROVER_assert(0, "sigsetjmp called directly");
11+
return 0;
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE unix
2+
main.c
3+
--pointer-check --bounds-check
4+
^\[main.assertion.1\] line 8 reached via siglongjmp: SUCCESS$
5+
^\[main.assertion.2\] line 10 sigsetjmp called directly: FAILURE$
6+
^VERIFICATION FAILED$
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
--
10+
^warning: ignoring

0 commit comments

Comments
 (0)