@@ -162,7 +162,13 @@ static checks_db get_analysis_report(std::ostream& s, cfg_t& cfg, const crab::in
162
162
return db;
163
163
}
164
164
165
- static thread_local std::optional<crab::invariant_table_t > save_pre_invariants = std::nullopt;
165
+ static thread_local std::optional<crab::invariant_table_t > saved_pre_invariants = std::nullopt;
166
+
167
+ static void save_invariants_if_needed (const crab::invariant_table_t & pre_invariants) {
168
+ if (thread_local_options.store_pre_invariants ) {
169
+ saved_pre_invariants = pre_invariants;
170
+ }
171
+ }
166
172
167
173
static checks_db get_ebpf_report (std::ostream& s, cfg_t & cfg, program_info info, const ebpf_verifier_options_t * options,
168
174
const std::optional<InstructionSeq>& prog = std::nullopt) {
@@ -175,9 +181,7 @@ static checks_db get_ebpf_report(std::ostream& s, cfg_t& cfg, program_info info,
175
181
// Get dictionaries of pre-invariants and post-invariants for each basic block.
176
182
ebpf_domain_t entry_dom = ebpf_domain_t::setup_entry (true );
177
183
auto [pre_invariants, post_invariants] = run_forward_analyzer (cfg, std::move (entry_dom));
178
- if (thread_local_options.store_pre_invariants ) {
179
- save_pre_invariants = pre_invariants;
180
- }
184
+ save_invariants_if_needed (pre_invariants);
181
185
return get_analysis_report (s, cfg, pre_invariants, post_invariants, prog);
182
186
} catch (std::runtime_error& e) {
183
187
// Convert verifier runtime_error exceptions to failure.
@@ -227,9 +231,7 @@ std::tuple<string_invariant, bool> ebpf_analyze_program_for_test(std::ostream& o
227
231
try {
228
232
cfg_t cfg = prepare_cfg (prog, info, options.simplify , false );
229
233
auto [pre_invariants, post_invariants] = run_forward_analyzer (cfg, std::move (entry_inv));
230
- if (thread_local_options.store_pre_invariants ) {
231
- save_pre_invariants = pre_invariants;
232
- }
234
+ save_invariants_if_needed (pre_invariants);
233
235
const checks_db report = get_analysis_report (std::cerr, cfg, pre_invariants, post_invariants);
234
236
print_report (os, report, prog, false );
235
237
@@ -276,21 +278,21 @@ void ebpf_verifier_clear_thread_local_state() {
276
278
global_program_info.clear ();
277
279
crab::domains::clear_thread_local_state ();
278
280
crab::domains::SplitDBM::clear_thread_local_state ();
279
- save_pre_invariants = std::nullopt;
281
+ saved_pre_invariants = std::nullopt;
280
282
}
281
283
282
284
bool ebpf_check_constraints_at_label (std::ostream& os, const std::string& label_string,
283
285
const std::set<std::string>& constraints) try {
284
286
label_t label = label_t (label_string);
285
- if (!save_pre_invariants .has_value ()) {
287
+ if (!saved_pre_invariants .has_value ()) {
286
288
os << " No pre-invariants available\n " ;
287
289
return false ;
288
290
}
289
- if (save_pre_invariants .value ().find (label) == save_pre_invariants .value ().end ()) {
291
+ if (saved_pre_invariants .value ().find (label) == saved_pre_invariants .value ().end ()) {
290
292
os << " No pre-invariants available for label " << label << " \n " ;
291
293
return false ;
292
294
}
293
- ebpf_domain_t from_inv (save_pre_invariants .value ().at (label));
295
+ ebpf_domain_t from_inv (saved_pre_invariants .value ().at (label));
294
296
auto concrete_domain = ebpf_domain_t::from_constraints (constraints, false );
295
297
296
298
if (concrete_domain.is_bottom ()) {
@@ -327,12 +329,14 @@ bool ebpf_check_constraints_at_label(std::ostream& os, const std::string& label_
327
329
328
330
std::set<std::string> ebpf_get_invariants_at_label (const std::string& label)
329
331
{
332
+ // If the label is malformed, throw an exception so the caller can handle it.
330
333
label_t l = label_t (label);
331
- if (!save_pre_invariants.has_value ()) {
334
+
335
+ if (!saved_pre_invariants.has_value ()) {
332
336
return {};
333
337
}
334
- if (save_pre_invariants .value ().find (l) == save_pre_invariants .value ().end ()) {
338
+ if (saved_pre_invariants .value ().find (l) == saved_pre_invariants .value ().end ()) {
335
339
return {};
336
340
}
337
- return save_pre_invariants .value ().at (l).to_set ().value ();
341
+ return saved_pre_invariants .value ().at (l).to_set ().value ();
338
342
}
0 commit comments