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
7f37f6af
Unverified
Commit
7f37f6af
authored
Jul 07, 2021
by
Melvin Klimke
Committed by
GitHub
Jul 07, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapt datatype conversion (#201)
parent
4746e4d3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
9 deletions
+25
-9
mod.rs
src/cwe_checker_lib/src/intermediate_representation/mod.rs
+4
-3
term.rs
src/cwe_checker_lib/src/intermediate_representation/term.rs
+10
-0
arguments.rs
src/cwe_checker_lib/src/utils/arguments.rs
+10
-5
tests.rs
src/cwe_checker_lib/src/utils/arguments/tests.rs
+1
-1
No files found.
src/cwe_checker_lib/src/intermediate_representation/mod.rs
View file @
7f37f6af
...
@@ -152,13 +152,14 @@ pub enum Datatype {
...
@@ -152,13 +152,14 @@ pub enum Datatype {
impl
From
<
String
>
for
Datatype
{
impl
From
<
String
>
for
Datatype
{
/// The purpose of this conversion is to locate parameters to variadic functions.
/// The purpose of this conversion is to locate parameters to variadic functions.
/// Therefore, char types
are mapped to integer types
since they undergo the default
/// Therefore, char types
have to be mapped to the integer size
since they undergo the default
/// argument promotion. (e.g. 1 byte char -> 4 byte integer)
/// argument promotion. (e.g. 1 byte char -> 4 byte integer)
/// The same holds for all float types that are promoted to doubles. (e.g. 8 byte float -> 16 byte double)
/// The same holds for all float types that are promoted to doubles. (e.g. 8 byte float -> 16 byte double)
fn
from
(
specifier
:
String
)
->
Self
{
fn
from
(
specifier
:
String
)
->
Self
{
match
specifier
.as_str
()
{
match
specifier
.as_str
()
{
"c"
|
"C"
|
"d"
|
"i"
|
"u"
|
"o"
|
"x"
|
"X"
|
"hi"
|
"hd"
|
"hu"
=>
Datatype
::
Integer
,
"c"
|
"C"
=>
Datatype
::
Char
,
"s"
|
"S"
|
"n"
|
"p"
=>
Datatype
::
Pointer
,
"d"
|
"i"
|
"u"
|
"o"
|
"p"
|
"x"
|
"X"
|
"hi"
|
"hd"
|
"hu"
=>
Datatype
::
Integer
,
"s"
|
"S"
|
"n"
=>
Datatype
::
Pointer
,
"lf"
|
"lg"
|
"le"
|
"la"
|
"lF"
|
"lG"
|
"lE"
|
"lA"
|
"f"
|
"F"
|
"e"
|
"E"
|
"a"
"lf"
|
"lg"
|
"le"
|
"la"
|
"lF"
|
"lG"
|
"lE"
|
"lA"
|
"f"
|
"F"
|
"e"
|
"E"
|
"a"
|
"A"
|
"g"
|
"G"
=>
Datatype
::
Double
,
|
"A"
|
"g"
|
"G"
=>
Datatype
::
Double
,
"li"
|
"ld"
|
"lu"
=>
Datatype
::
Long
,
"li"
|
"ld"
|
"lu"
=>
Datatype
::
Long
,
...
...
src/cwe_checker_lib/src/intermediate_representation/term.rs
View file @
7f37f6af
...
@@ -475,6 +475,16 @@ pub enum Arg {
...
@@ -475,6 +475,16 @@ pub enum Arg {
},
},
}
}
impl
Arg
{
/// Returns the data type field of an Arg object.
pub
fn
get_data_type
(
&
self
)
->
Option
<
Datatype
>
{
match
self
{
Arg
::
Register
{
data_type
,
..
}
=>
data_type
.clone
(),
Arg
::
Stack
{
data_type
,
..
}
=>
data_type
.clone
(),
}
}
}
/// An extern symbol represents a funtion that is dynamically linked from another binary.
/// An extern symbol represents a funtion that is dynamically linked from another binary.
#[derive(Serialize,
Deserialize,
Debug,
PartialEq,
Eq,
Hash,
Clone)]
#[derive(Serialize,
Deserialize,
Debug,
PartialEq,
Eq,
Hash,
Clone)]
pub
struct
ExternSymbol
{
pub
struct
ExternSymbol
{
...
...
src/cwe_checker_lib/src/utils/arguments.rs
View file @
7f37f6af
...
@@ -90,10 +90,15 @@ pub fn parse_format_string_parameters(
...
@@ -90,10 +90,15 @@ pub fn parse_format_string_parameters(
.captures_iter
(
format_string
)
.captures_iter
(
format_string
)
.map
(|
cap
|
{
.map
(|
cap
|
{
let
data_type
=
Datatype
::
from
(
cap
[
1
]
.to_string
());
let
data_type
=
Datatype
::
from
(
cap
[
1
]
.to_string
());
(
let
size
=
{
data_type
.clone
(),
// Considers argument promotion for char type
datatype_properties
.get_size_from_data_type
(
data_type
),
if
matches!
(
data_type
,
Datatype
::
Char
)
{
)
datatype_properties
.get_size_from_data_type
(
Datatype
::
Integer
)
}
else
{
datatype_properties
.get_size_from_data_type
(
data_type
.clone
())
}
};
(
data_type
,
size
)
})
})
.collect
();
.collect
();
...
@@ -169,7 +174,7 @@ pub fn calculate_parameter_locations(
...
@@ -169,7 +174,7 @@ pub fn calculate_parameter_locations(
for
(
data_type
,
size
)
in
parameters
.iter
()
{
for
(
data_type
,
size
)
in
parameters
.iter
()
{
match
data_type
{
match
data_type
{
Datatype
::
Integer
|
Datatype
::
Pointer
=>
{
Datatype
::
Integer
|
Datatype
::
Pointer
|
Datatype
::
Char
=>
{
if
integer_arg_register_count
>
0
{
if
integer_arg_register_count
>
0
{
let
register_name
=
calling_convention
.integer_parameter_register
let
register_name
=
calling_convention
.integer_parameter_register
[
calling_convention
.integer_parameter_register
.len
()
[
calling_convention
.integer_parameter_register
.len
()
...
...
src/cwe_checker_lib/src/utils/arguments/tests.rs
View file @
7f37f6af
...
@@ -37,7 +37,7 @@ fn test_get_variable_parameters() {
...
@@ -37,7 +37,7 @@ fn test_get_variable_parameters() {
output
.push
(
Arg
::
Stack
{
output
.push
(
Arg
::
Stack
{
offset
:
0
,
offset
:
0
,
size
:
ByteSize
::
new
(
4
),
size
:
ByteSize
::
new
(
4
),
data_type
:
Some
(
Datatype
::
Intege
r
),
data_type
:
Some
(
Datatype
::
Cha
r
),
});
});
output
.push
(
Arg
::
Stack
{
output
.push
(
Arg
::
Stack
{
...
...
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