Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cwe_checker
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
cwe_checker
Commits
1fcc30cb
Unverified
Commit
1fcc30cb
authored
May 12, 2023
by
Enkelmann
Committed by
GitHub
May 12, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent panic on non-converging globals propagation (#409)
parent
d84f5170
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
5 deletions
+15
-5
global_var_propagation.rs
...src/analysis/function_signature/global_var_propagation.rs
+14
-4
mod.rs
src/cwe_checker_lib/src/analysis/function_signature/mod.rs
+1
-1
No files found.
src/cwe_checker_lib/src/analysis/function_signature/global_var_propagation.rs
View file @
1fcc30cb
...
...
@@ -10,6 +10,7 @@ use crate::analysis::callgraph::get_program_callgraph;
use
crate
::
analysis
::
callgraph
::
CallGraph
;
use
crate
::
analysis
::
fixpoint
::{
Computation
,
Context
};
use
crate
::
intermediate_representation
::
*
;
use
crate
::
utils
::
log
::
LogMessage
;
use
std
::
collections
::
BTreeMap
;
use
std
::
collections
::
HashSet
;
...
...
@@ -162,6 +163,7 @@ fn propagate_globals_bottom_up(
project
:
&
Project
,
known_globals
:
&
BTreeMap
<
Tid
,
HashSet
<
u64
>>
,
fn_sigs
:
&
mut
BTreeMap
<
Tid
,
FunctionSignature
>
,
logs
:
&
mut
Vec
<
LogMessage
>
,
)
{
// To propagate bottom-up, we have to reverse the edges in the callgraph
let
mut
graph
=
get_program_callgraph
(
&
project
.program
);
...
...
@@ -183,7 +185,11 @@ fn propagate_globals_bottom_up(
// Compute the fixpoint
computation
.compute_with_max_steps
(
100
);
if
!
computation
.has_stabilized
()
{
panic!
(
"Global parameter propagation algorithm did not stabilize."
)
let
error_msg
=
format!
(
"Global parameter propagation algorithm did not stabilize. Remaining worklist size: {}"
,
computation
.get_worklist
()
.len
()
);
logs
.push
(
LogMessage
::
new_error
(
error_msg
)
.source
(
"Function Signature Analysis"
));
}
// Add the propagated globals to the function signatures
for
node
in
graph
.node_indices
()
{
...
...
@@ -217,9 +223,13 @@ fn propagate_globals_bottom_up(
/// But if the function itself (or any of its callers) do not access the global variable,
/// then there is no benefit in tracking its value for the function itself.
/// Thus, the global variable should not be propagated to the function in such a case.
pub
fn
propagate_globals
(
project
:
&
Project
,
fn_sigs
:
&
mut
BTreeMap
<
Tid
,
FunctionSignature
>
)
{
pub
fn
propagate_globals
(
project
:
&
Project
,
fn_sigs
:
&
mut
BTreeMap
<
Tid
,
FunctionSignature
>
,
logs
:
&
mut
Vec
<
LogMessage
>
,
)
{
let
known_globals
=
propagate_known_globals_top_down
(
project
,
fn_sigs
);
propagate_globals_bottom_up
(
project
,
&
known_globals
,
fn_sigs
);
propagate_globals_bottom_up
(
project
,
&
known_globals
,
fn_sigs
,
logs
);
}
#[cfg(test)]
...
...
@@ -271,7 +281,7 @@ pub mod tests {
]);
// Propagate globals
propagate_globals
(
&
project
,
&
mut
fn_sigs
);
propagate_globals
(
&
project
,
&
mut
fn_sigs
,
&
mut
Vec
::
new
()
);
// Check propagation results
assert_eq!
(
&
fn_sigs
[
&
Tid
::
new
(
"main"
)]
.global_parameters
,
...
...
src/cwe_checker_lib/src/analysis/function_signature/mod.rs
View file @
1fcc30cb
...
...
@@ -168,7 +168,7 @@ pub fn compute_function_signatures<'a>(
}
}
// Propagate globals in bottom-up direction in the call graph
propagate_globals
(
project
,
&
mut
fn_sig_map
);
propagate_globals
(
project
,
&
mut
fn_sig_map
,
&
mut
logs
);
(
fn_sig_map
,
logs
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment