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
44ec840b
Unverified
Commit
44ec840b
authored
Jul 20, 2022
by
van den Bosch
Committed by
GitHub
Jul 20, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added Display trait for Expressions and Operands (#341)
parent
78575b7b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
163 additions
and
4 deletions
+163
-4
mod.rs
src/cwe_checker_lib/src/analysis/pointer_inference/mod.rs
+1
-1
cwe_467.rs
src/cwe_checker_lib/src/checkers/cwe_467.rs
+1
-1
cwe_560.rs
src/cwe_checker_lib/src/checkers/cwe_560.rs
+1
-1
blk.rs
src/cwe_checker_lib/src/intermediate_representation/blk.rs
+13
-1
def.rs
src/cwe_checker_lib/src/intermediate_representation/def.rs
+12
-0
expression.rs
...checker_lib/src/intermediate_representation/expression.rs
+77
-0
tests.rs
...r_lib/src/intermediate_representation/expression/tests.rs
+24
-0
jmp.rs
src/cwe_checker_lib/src/intermediate_representation/jmp.rs
+34
-0
No files found.
src/cwe_checker_lib/src/analysis/pointer_inference/mod.rs
View file @
44ec840b
...
...
@@ -156,7 +156,7 @@ impl<'a> PointerInference<'a> {
}
if
!
self
.computation
.has_stabilized
()
{
let
worklist_size
=
self
.computation
.get_worklist
()
.len
();
let
_
=
self
.log_info
(
format!
(
self
.log_info
(
format!
(
"Fixpoint did not stabilize. Remaining worklist size: {}"
,
worklist_size
,
));
...
...
src/cwe_checker_lib/src/checkers/cwe_467.rs
View file @
44ec840b
...
...
@@ -54,7 +54,7 @@ fn compute_block_end_state(project: &Project, block: &Term<Blk>) -> State {
let
_
=
state
.handle_store
(
address
,
value
,
&
project
.runtime_memory_image
);
}
Def
::
Assign
{
var
,
value
}
=>
{
let
_
=
state
.handle_register_assign
(
var
,
value
);
state
.handle_register_assign
(
var
,
value
);
}
Def
::
Load
{
var
,
address
}
=>
{
let
_
=
state
.handle_load
(
var
,
address
,
&
project
.runtime_memory_image
);
...
...
src/cwe_checker_lib/src/checkers/cwe_560.rs
View file @
44ec840b
...
...
@@ -59,7 +59,7 @@ fn get_umask_permission_arg(
let
_
=
state
.handle_store
(
address
,
value
,
&
project
.runtime_memory_image
);
}
Def
::
Assign
{
var
,
value
}
=>
{
let
_
=
state
.handle_register_assign
(
var
,
value
);
state
.handle_register_assign
(
var
,
value
);
}
Def
::
Load
{
var
,
address
}
=>
{
let
_
=
state
.handle_load
(
var
,
address
,
&
project
.runtime_memory_image
);
...
...
src/cwe_checker_lib/src/intermediate_representation/blk.rs
View file @
44ec840b
use
super
::
*
;
use
crate
::
utils
::
log
::
LogMessage
;
use
std
::
collections
::
HashSet
;
use
std
::
{
collections
::
HashSet
,
fmt
}
;
/// A basic block is a sequence of `Def` instructions followed by up to two `Jmp` instructions.
///
...
...
@@ -188,6 +188,18 @@ impl Term<Blk> {
}
}
impl
fmt
::
Display
for
Blk
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
for
def
in
self
.defs
.iter
()
{
writeln!
(
f
,
"{}: {}"
,
def
.tid
,
def
.term
)
?
;
}
for
jmp
in
self
.jmps
.iter
()
{
writeln!
(
f
,
"{}: {}"
,
jmp
.tid
,
jmp
.term
)
?
;
}
Ok
(())
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
...
...
src/cwe_checker_lib/src/intermediate_representation/def.rs
View file @
44ec840b
use
std
::
fmt
;
use
super
::{
CastOpType
,
Expression
,
Variable
};
use
crate
::
prelude
::
*
;
...
...
@@ -86,6 +88,16 @@ impl Term<Def> {
}
}
impl
fmt
::
Display
for
Def
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
match
self
{
Def
::
Load
{
var
,
address
}
=>
write!
(
f
,
"{} := Load from {}"
,
var
,
address
),
Def
::
Store
{
address
,
value
}
=>
write!
(
f
,
"Store at {} := {}"
,
address
,
value
),
Def
::
Assign
{
var
,
value
}
=>
write!
(
f
,
"{} = {}"
,
var
,
value
),
}
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
...
...
src/cwe_checker_lib/src/intermediate_representation/expression.rs
View file @
44ec840b
use
std
::
collections
::
HashMap
;
use
std
::
fmt
::{
self
,
Debug
};
use
super
::
Variable
;
use
super
::{
ByteSize
,
Def
};
...
...
@@ -431,5 +432,81 @@ impl Expression {
}
}
impl
fmt
::
Display
for
Expression
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
match
self
{
Expression
::
Var
(
var
)
=>
write!
(
f
,
"{}"
,
var
),
Expression
::
Const
(
c
)
=>
{
write!
(
f
,
"0x{:016x}:i{}"
,
c
,
c
.bytesize
()
.as_bit_length
())
}
Expression
::
BinOp
{
op
,
lhs
,
rhs
}
=>
match
op
{
BinOpType
::
IntMult
|
BinOpType
::
IntDiv
|
BinOpType
::
IntRem
|
BinOpType
::
FloatMult
|
BinOpType
::
FloatDiv
=>
write!
(
f
,
"{} {} {}"
,
lhs
,
op
,
rhs
),
_
=>
write!
(
f
,
"({} {} {})"
,
lhs
,
op
,
rhs
),
},
Expression
::
UnOp
{
op
,
arg
}
=>
write!
(
f
,
"{}({})"
,
op
,
arg
),
Expression
::
Cast
{
op
,
size
:
_
,
arg
}
=>
write!
(
f
,
"{}({})"
,
op
,
arg
),
Expression
::
Unknown
{
description
,
size
:
_
,
}
=>
write!
(
f
,
"{}"
,
description
),
Expression
::
Subpiece
{
low_byte
,
size
,
arg
,
}
=>
{
if
let
(
Ok
(
start
),
Ok
(
end
))
=
(
u32
::
try_from
(
low_byte
.
0
),
u32
::
try_from
(
size
.
0
))
{
write!
(
f
,
"({})[{}-{}]"
,
arg
,
start
,
end
)
}
else
{
write!
(
f
,
"{}[]"
,
arg
)
}
}
}
}
}
impl
fmt
::
Display
for
BinOpType
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
match
self
{
BinOpType
::
IntEqual
=>
write!
(
f
,
"=="
),
BinOpType
::
IntNotEqual
=>
write!
(
f
,
"!="
),
BinOpType
::
IntLess
=>
write!
(
f
,
"<"
),
BinOpType
::
IntSLess
=>
write!
(
f
,
"<"
),
BinOpType
::
IntLessEqual
=>
write!
(
f
,
"<="
),
BinOpType
::
IntSLessEqual
=>
write!
(
f
,
"<="
),
BinOpType
::
IntAdd
=>
write!
(
f
,
"+"
),
BinOpType
::
IntSub
=>
write!
(
f
,
"-"
),
BinOpType
::
IntXOr
=>
write!
(
f
,
"^"
),
BinOpType
::
IntAnd
=>
write!
(
f
,
"&"
),
BinOpType
::
IntOr
=>
write!
(
f
,
"|"
),
BinOpType
::
IntLeft
=>
write!
(
f
,
"<<"
),
BinOpType
::
IntRight
=>
write!
(
f
,
">>"
),
BinOpType
::
IntMult
=>
write!
(
f
,
"*"
),
BinOpType
::
IntDiv
=>
write!
(
f
,
"/"
),
BinOpType
::
IntRem
=>
write!
(
f
,
"
%
"
),
BinOpType
::
BoolAnd
=>
write!
(
f
,
"&&"
),
BinOpType
::
BoolOr
=>
write!
(
f
,
"||"
),
_
=>
write!
(
f
,
"{:?}"
,
self
),
}
}
}
impl
fmt
::
Display
for
UnOpType
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
match
self
{
UnOpType
::
BoolNegate
=>
write!
(
f
,
"¬"
),
_
=>
write!
(
f
,
"{:?}"
,
self
),
}
}
}
impl
fmt
::
Display
for
CastOpType
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
write!
(
f
,
"{:?}"
,
self
)
}
}
#[cfg(test)]
mod
tests
;
src/cwe_checker_lib/src/intermediate_representation/expression/tests.rs
View file @
44ec840b
...
...
@@ -539,3 +539,27 @@ fn processing_sub_registers() {
expr
.cast_sub_registers_to_base_register_subpieces
(
output
,
&
register_map
,
peeked
);
assert_eq!
(
expr
,
setup
.int_sub_subpiece_expr
);
}
#[test]
fn
display
()
{
let
expr
=
Expression
::
const_from_i32
(
2
);
let
mul
=
Expression
::
BinOp
{
op
:
BinOpType
::
IntMult
,
lhs
:
Box
::
new
(
Expression
::
Var
(
Variable
::
mock
(
"RAX"
,
8
))),
rhs
:
Box
::
new
(
Expression
::
Var
(
Variable
::
mock
(
"RBP"
,
8
))),
};
let
expr
=
expr
.plus
(
mul
);
let
expr
=
Expression
::
UnOp
{
op
:
UnOpType
::
IntNegate
,
arg
:
Box
::
new
(
expr
),
};
let
expr
=
expr
.cast
(
CastOpType
::
IntSExt
)
.un_op
(
UnOpType
::
FloatCeil
)
.subpiece
(
ByteSize
(
0
),
ByteSize
(
20
));
assert_eq!
(
"(FloatCeil(IntSExt(IntNegate((0x2:i32 + RAX:64 * RBP:64)))))[0-20]"
,
format!
(
"{}"
,
expr
)
);
}
src/cwe_checker_lib/src/intermediate_representation/jmp.rs
View file @
44ec840b
use
std
::
fmt
;
use
super
::
Expression
;
use
crate
::
prelude
::
*
;
...
...
@@ -58,3 +60,35 @@ pub enum Jmp {
return_
:
Option
<
Tid
>
,
},
}
impl
fmt
::
Display
for
Jmp
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
match
self
{
Jmp
::
Branch
(
tid
)
=>
write!
(
f
,
"Jump to {}"
,
tid
),
Jmp
::
BranchInd
(
expr
)
=>
write!
(
f
,
"Jump to {}"
,
expr
),
Jmp
::
CBranch
{
target
,
condition
}
=>
write!
(
f
,
"If {} jump to {}"
,
condition
,
target
),
Jmp
::
Call
{
target
,
return_
}
=>
write!
(
f
,
"call {} ret {}"
,
target
,
return_
.as_ref
()
.unwrap_or
(
&
Tid
::
new
(
"?"
))
),
Jmp
::
CallInd
{
target
,
return_
}
=>
write!
(
f
,
"call {} ret {}"
,
target
,
return_
.as_ref
()
.unwrap_or
(
&
Tid
::
new
(
"?"
))
),
Jmp
::
Return
(
expr
)
=>
write!
(
f
,
"ret {}"
,
expr
),
Jmp
::
CallOther
{
description
,
return_
,
}
=>
write!
(
f
,
"call {} ret {}"
,
description
,
return_
.as_ref
()
.unwrap_or
(
&
Tid
::
new
(
"?"
))
),
}
}
}
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