Skip to content

Commit 959c7a5

Browse files
committed
Bugfix: Maintain safe_pointers per-path
The map of safe pointers is now maintained separately for each path, ensuring that pointer accesses on one path do not influence a (lack of) pointer accesses on a different path. This commit fixes #2866, a segfault that would happen when running CBMC on the included regression test.
1 parent 2b5e925 commit 959c7a5

File tree

7 files changed

+35
-8
lines changed

7 files changed

+35
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
int foo(int *x)
2+
{
3+
if(*x)
4+
{
5+
int y = 9;
6+
}
7+
else
8+
{
9+
int z = 4;
10+
}
11+
}
12+
13+
int main()
14+
{
15+
int x;
16+
foo(&x);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--paths lifo
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/goto-symex/goto_symex.h

-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ Author: Daniel Kroening, [email protected]
1212
#ifndef CPROVER_GOTO_SYMEX_GOTO_SYMEX_H
1313
#define CPROVER_GOTO_SYMEX_GOTO_SYMEX_H
1414

15-
#include <analyses/local_safe_pointers.h>
16-
1715
#include <util/options.h>
1816
#include <util/message.h>
1917

@@ -468,8 +466,6 @@ class goto_symext
468466
void rewrite_quantifiers(exprt &, statet &);
469467

470468
path_storaget &path_storage;
471-
472-
std::unordered_map<irep_idt, local_safe_pointerst> safe_pointers;
473469
};
474470

475471
#endif // CPROVER_GOTO_SYMEX_GOTO_SYMEX_H

src/goto-symex/goto_symex_state.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616
#include <unordered_set>
1717

1818
#include <analyses/dirty.h>
19+
#include <analyses/local_safe_pointers.h>
1920

2021
#include <util/invariant.h>
2122
#include <util/guard.h>
@@ -197,6 +198,8 @@ class goto_symex_statet final
197198
l1_typest l1_types;
198199

199200
public:
201+
std::unordered_map<irep_idt, local_safe_pointerst> safe_pointers;
202+
200203
// uses level 1 names, and is used to
201204
// do dereferencing
202205
value_sett value_set;
@@ -211,6 +214,7 @@ class goto_symex_statet final
211214
symex_targett::sourcet source;
212215
propagationt propagation;
213216
unsigned atomic_section_id;
217+
std::unordered_map<irep_idt, local_safe_pointerst> safe_pointers;
214218

215219
explicit goto_statet(const goto_symex_statet &s):
216220
depth(s.depth),
@@ -219,7 +223,8 @@ class goto_symex_statet final
219223
guard(s.guard),
220224
source(s.source),
221225
propagation(s.propagation),
222-
atomic_section_id(s.atomic_section_id)
226+
atomic_section_id(s.atomic_section_id),
227+
safe_pointers(s.safe_pointers)
223228
{
224229
}
225230

@@ -247,6 +252,7 @@ class goto_symex_statet final
247252
guard(s.guard),
248253
source(s.source),
249254
propagation(s.propagation),
255+
safe_pointers(s.safe_pointers),
250256
value_set(s.value_set),
251257
atomic_section_id(s.atomic_section_id)
252258
{

src/goto-symex/symex_dereference.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void goto_symext::dereference_rec(
247247
state.get_original_name(to_check);
248248

249249
expr_is_not_null =
250-
safe_pointers.at(expr_function).is_safe_dereference(
250+
state.safe_pointers.at(expr_function).is_safe_dereference(
251251
to_check, state.source.pc);
252252
}
253253
}

src/goto-symex/symex_function_call.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ void goto_symext::symex_function_call_code(
225225
state.dirty.populate_dirty_for_function(identifier, goto_function);
226226

227227
auto emplace_safe_pointers_result =
228-
safe_pointers.emplace(identifier, local_safe_pointerst{ns});
228+
state.safe_pointers.emplace(identifier, local_safe_pointerst{ns});
229229
if(emplace_safe_pointers_result.second)
230230
emplace_safe_pointers_result.first->second(goto_function.body);
231231

src/goto-symex/symex_main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void goto_symext::initialize_entry_point(
136136
const goto_functiont &entry_point_function = get_goto_function(pc->function);
137137

138138
auto emplace_safe_pointers_result =
139-
safe_pointers.emplace(pc->function, local_safe_pointerst{ns});
139+
state.safe_pointers.emplace(pc->function, local_safe_pointerst{ns});
140140
if(emplace_safe_pointers_result.second)
141141
emplace_safe_pointers_result.first->second(entry_point_function.body);
142142

0 commit comments

Comments
 (0)