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
d753fbc4
Unverified
Commit
d753fbc4
authored
Jan 28, 2020
by
Enkelmann
Committed by
GitHub
Jan 28, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enabled unittests for Travis CI. Fixed get_program_entry_points. (#48)
Unit tests no longer fail silently on Travis CI builds.
parent
3ccc1062
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
19 additions
and
10 deletions
+19
-10
.travis_run_tests.sh
.travis_run_tests.sh
+1
-2
cwe_248.ml
src/checkers/cwe_248.ml
+1
-1
symbol_utils.ml
src/utils/symbol_utils.ml
+8
-3
symbol_utils.mli
src/utils/symbol_utils.mli
+3
-1
cwe_checker_unit_tests.ml
test/unit/cwe_checker_unit_tests.ml
+5
-1
cconv_test.ml
test/unit/utils/cconv_test.ml
+1
-2
No files found.
.travis_run_tests.sh
View file @
d753fbc4
#!/bin/bash
dune runtest
pytest
docker run
--rm
-t
cwe-checker dune runtest
&&
pytest
src/checkers/cwe_248.ml
View file @
d753fbc4
...
...
@@ -61,5 +61,5 @@ let rec find_uncaught_exceptions subfunction already_checked_functions program ~
way. We should check whether this produces a lot of false negatives. *)
let
check_cwe
program
_project
tid_map
_symbol_pairs
_
=
let
entry_points
=
Symbol_utils
.
get_program_entry_points
program
in
let
_
=
Seq
.
fold
entry_points
~
init
:
[]
~
f
:
(
fun
already_checked_functions
sub
->
find_uncaught_exceptions
~
tid_map
:
tid_map
sub
already_checked_functions
program
)
in
let
_
=
List
.
fold
entry_points
~
init
:
[]
~
f
:
(
fun
already_checked_functions
sub
->
find_uncaught_exceptions
~
tid_map
:
tid_map
sub
already_checked_functions
program
)
in
()
src/utils/symbol_utils.ml
View file @
d753fbc4
...
...
@@ -165,11 +165,16 @@ let extract_direct_call_tid_from_block block =
Some
(
tid
)
|
_
->
None
)
let
get_program_entry_points
program
=
let
get_program_entry_points
(
program
:
Program
.
t
)
:
Sub
.
t
List
.
t
=
let
subfunctions
=
Term
.
enum
sub_t
program
in
let
entry_points
=
Seq
.
filter
subfunctions
~
f
:
(
fun
subfn
->
Term
.
has_attr
subfn
Sub
.
entry_point
)
in
let
main_fn
=
Seq
.
filter
subfunctions
~
f
:
(
fun
subfn
->
"@main"
=
Tid
.
name
(
Term
.
tid
subfn
))
in
Seq
.
append
main_fn
entry_points
match
Seq
.
find
subfunctions
~
f
:
(
fun
subfn
->
"main"
=
Sub
.
name
subfn
)
with
|
Some
(
main_fn
)
->
if
Seq
.
exists
entry_points
~
f
:
(
fun
elem
->
elem
=
main_fn
)
then
Seq
.
to_list
entry_points
else
main_fn
::
(
Seq
.
to_list
entry_points
)
|
None
->
Seq
.
to_list
entry_points
let
stack_register
project
=
let
arch
=
Project
.
arch
project
in
...
...
src/utils/symbol_utils.mli
View file @
d753fbc4
(** This module implements functionality to work with symbols (e.g. malloc).*)
open
Core_kernel
type
concrete_call
=
{
call_site
:
Bap
.
Std
.
tid
;
symbol_address
:
Bap
.
Std
.
tid
...
...
@@ -76,7 +78,7 @@ val extract_direct_call_tid_from_block : Bap.Std.blk Bap.Std.term -> Bap.Std.tid
(** Returns a sequence of all entry points of the program.
TODO: The _start entry point usually calls a libc-function which then calls the main function. Since right now only direct
calls are tracked, our graph traversal may never find the main function. For now, we add it by hand to the entry points. *)
val
get_program_entry_points
:
Bap
.
Std
.
program
Bap
.
Std
.
term
->
Bap
.
Std
.
sub
Bap
.
Std
.
term
Bap
.
Std
.
Seq
.
t
val
get_program_entry_points
:
Bap
.
Std
.
program
Bap
.
Std
.
term
->
Bap
.
Std
.
sub
Bap
.
Std
.
term
List
.
t
(** Returns the stack register on the architecture of the given project. *)
val
stack_register
:
Bap
.
Std
.
Project
.
t
->
Bap
.
Std
.
Var
.
t
...
...
test/unit/cwe_checker_unit_tests.ml
View file @
d753fbc4
...
...
@@ -22,5 +22,9 @@ let () =
Project
.
register_pass'
run_tests
else
(* The file was run as a standalone executable. Use make to build and run the unit test plugin *)
let
()
=
Sys
.
chdir
(
Sys
.
getenv
"PWD"
^
"/test/unit"
)
in
let
()
=
try
Sys
.
chdir
(
Sys
.
getenv
"PWD"
^
"/test/unit"
)
with
_
->
(* In the docker image the environment variable PWD is not set *)
Sys
.
chdir
"/home/bap/cwe_checker/test/unit"
in
exit
(
Sys
.
command
"make all"
)
test/unit/utils/cconv_test.ml
View file @
d753fbc4
...
...
@@ -41,8 +41,7 @@ let test_parse_dyn_syms () =
let
()
=
check
"free_as_dyn_sym"
(
String
.
Set
.
mem
(
parse_dyn_syms
project
)
"free"
)
in
let
()
=
check
"__libc_start_main_as_dyn_sym"
(
String
.
Set
.
mem
(
parse_dyn_syms
project
)
"__libc_start_main"
)
in
let
()
=
check
"malloc_as_dyn_sym"
(
String
.
Set
.
mem
(
parse_dyn_syms
project
)
"malloc"
)
in
let
()
=
check
"__cxa_finalize_as_dyn_sym"
(
String
.
Set
.
mem
(
parse_dyn_syms
project
)
"__cxa_finalize"
)
in
let
()
=
check
"dyn_sym_count"
(
String
.
Set
.
count
(
parse_dyn_syms
project
)
~
f
:
(
fun
_elem
->
true
)
=
4
)
in
let
()
=
check
"realloc_not_a_dyn_sym"
(
false
=
String
.
Set
.
mem
(
parse_dyn_syms
project
)
"realloc"
)
in
()
let
tests
=
[
...
...
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