Skip to content

Commit 2125370

Browse files
authored
Merge pull request #1210 from goblint/longjmp-top
Fix longjmp crash on Uninitialized
2 parents fe36915 + 5948ca4 commit 2125370

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/analyses/base.ml

+9-2
Original file line numberDiff line numberDiff line change
@@ -1231,9 +1231,16 @@ struct
12311231
if copied then
12321232
M.warn ~category:(Behavior (Undefined Other)) "The jump buffer %a contains values that were copied here instead of being set by setjmp. This is Undefined Behavior." d_exp e;
12331233
x
1234-
| y -> failwith (GobPretty.sprintf "problem?! is %a %a:\n state is %a" CilType.Exp.pretty e VD.pretty y D.pretty ctx.local)
1234+
| Top
1235+
| Bot ->
1236+
JmpBufDomain.JmpBufSet.top ()
1237+
| y ->
1238+
M.debug ~category:Imprecise "EvalJmpBuf %a is %a, not JmpBuf." CilType.Exp.pretty e VD.pretty y;
1239+
JmpBufDomain.JmpBufSet.top ()
12351240
end
1236-
| _ -> failwith "problem?!"
1241+
| _ ->
1242+
M.debug ~category:Imprecise "EvalJmpBuf is not Address";
1243+
JmpBufDomain.JmpBufSet.top ()
12371244
end
12381245
| Q.EvalInt e ->
12391246
query_evalint (Analyses.ask_of_ctx ctx) ctx.global ctx.local e

src/framework/constraints.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,8 @@ struct
16631663
if M.tracing then Messages.tracel "longjmp" "Jumping to %a\n" JmpBufDomain.JmpBufSet.pretty targets;
16641664
let handle_target target = match target with
16651665
| JmpBufDomain.BufferEntryOrTop.AllTargets ->
1666-
M.warn ~category:Imprecise "Longjmp to potentially invalid target, as contents of buffer %a may be unknown! (imprecision due to heap?)" d_exp env
1666+
M.warn ~category:Imprecise "Longjmp to potentially invalid target, as contents of buffer %a may be unknown! (imprecision due to heap?)" d_exp env;
1667+
M.msg_final Error ~category:Unsound ~tags:[Category Imprecise; Category Call] "Longjmp to unknown target ignored"
16671668
| Target (target_node, target_context) ->
16681669
let target_fundec = Node.find_fundec target_node in
16691670
if CilType.Fundec.equal target_fundec current_fundec && ControlSpecC.equal target_context (ctx.control_context ()) then (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Extracted from concrat/pigz.
2+
#include <setjmp.h>
3+
#include <pthread.h>
4+
#include <goblint.h>
5+
6+
pthread_key_t buf_key;
7+
8+
int main() {
9+
jmp_buf buf;
10+
pthread_setspecific(buf_key, &buf);
11+
12+
if (!setjmp(buf)) {
13+
jmp_buf *buf_ptr;
14+
buf_ptr = pthread_getspecific(buf_key);
15+
longjmp(*buf_ptr, 1); // NO CRASH: problem?!
16+
}
17+
else {
18+
__goblint_check(1); // TODO reachable: https://github.com/goblint/analyzer/pull/1210#discussion_r1350021903
19+
}
20+
return 0;
21+
}

0 commit comments

Comments
 (0)