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
bd2ceba3
Commit
bd2ceba3
authored
Jan 18, 2019
by
Thomas Barabosch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring: created module for JSON related functions.
parent
a6057e2c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
25 deletions
+31
-25
cwe_checker.ml
src/cwe_checker.ml
+2
-25
json_utils.ml
src/utils/json_utils.ml
+25
-0
json_utils.mli
src/utils/json_utils.mli
+4
-0
No files found.
src/cwe_checker.ml
View file @
bd2ceba3
...
@@ -34,29 +34,6 @@ let print_module_versions () =
...
@@ -34,29 +34,6 @@ let print_module_versions () =
"[cwe_checker] module_versions: (%s)"
"[cwe_checker] module_versions: (%s)"
(
build_version_sexp
()
)
(
build_version_sexp
()
)
(** Extracts the symbols to check for from json document.
An example looks like this:
"CWE467": {
"symbols": ["strncmp", "malloc",
"alloca", "_alloca", "strncat", "wcsncat",
"strncpy", "wcsncpy", "stpncpy", "wcpncpy",
"memcpy", "wmemcpy", "memmove", "wmemmove", "memcmp", "wmemcmp"],
"_comment": "any function that takes something of type size_t could be a possible candidate."
}, *)
let
get_symbols_from_json
json
cwe
=
[
json
]
|>
filter_member
cwe
|>
filter_member
"symbols"
|>
flatten
|>
List
.
map
~
f
:
to_string
let
get_symbol_lists_from_json
json
cwe
=
[
json
]
|>
filter_member
cwe
|>
filter_member
"pairs"
|>
flatten
|>
List
.
map
~
f
:
(
fun
l
->
List
.
map
(
to_list
l
)
~
f
:
to_string
)
let
partial_run
project
config
modules
=
let
partial_run
project
config
modules
=
let
program
=
Project
.
program
project
in
let
program
=
Project
.
program
project
in
let
tid_address_map
=
Address_translation
.
generate_tid_map
program
in
let
tid_address_map
=
Address_translation
.
generate_tid_map
program
in
...
@@ -70,12 +47,12 @@ let full_run project config =
...
@@ -70,12 +47,12 @@ let full_run project config =
begin
begin
List
.
iter
known_modules
~
f
:
(
fun
cwe
->
if
cwe
.
requires_pairs
=
true
then
List
.
iter
known_modules
~
f
:
(
fun
cwe
->
if
cwe
.
requires_pairs
=
true
then
begin
begin
let
symbol_pairs
=
get_symbol_lists_from_json
json
cwe
.
name
in
let
symbol_pairs
=
Json_utils
.
get_symbol_lists_from_json
json
cwe
.
name
in
cwe
.
cwe_func
program
project
tid_address_map
symbol_pairs
cwe
.
cwe_func
program
project
tid_address_map
symbol_pairs
end
end
else
else
begin
begin
let
symbols
=
get_symbols_from_json
json
cwe
.
name
in
let
symbols
=
Json_utils
.
get_symbols_from_json
json
cwe
.
name
in
cwe
.
cwe_func
program
project
tid_address_map
[
symbols
]
cwe
.
cwe_func
program
project
tid_address_map
[
symbols
]
end
)
end
)
end
end
...
...
src/utils/json_utils.ml
0 → 100644
View file @
bd2ceba3
open
Core_kernel
.
Std
open
Yojson
.
Basic
.
Util
(** Extracts the symbols to check for from json document.
An example looks like this:
"CWE467": {
"symbols": ["strncmp", "malloc",
"alloca", "_alloca", "strncat", "wcsncat",
"strncpy", "wcsncpy", "stpncpy", "wcpncpy",
"memcpy", "wmemcpy", "memmove", "wmemmove", "memcmp", "wmemcmp"],
"_comment": "any function that takes something of type size_t could be a possible candidate."
}, *)
let
get_symbols_from_json
json
cwe
=
[
json
]
|>
filter_member
cwe
|>
filter_member
"symbols"
|>
flatten
|>
List
.
map
~
f
:
to_string
let
get_symbol_lists_from_json
json
cwe
=
[
json
]
|>
filter_member
cwe
|>
filter_member
"pairs"
|>
flatten
|>
List
.
map
~
f
:
(
fun
l
->
List
.
map
(
to_list
l
)
~
f
:
to_string
)
src/utils/json_utils.mli
0 → 100644
View file @
bd2ceba3
(* This module implements functionality related to parsing the JSON configuration file. *)
val
get_symbol_lists_from_json
:
Yojson
.
Basic
.
json
->
string
->
string
list
list
val
get_symbols_from_json
:
Yojson
.
Basic
.
json
->
string
->
string
list
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