Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cwe248 #5

Merged
merged 11 commits into from
Jan 21, 2019
Merged

Cwe248 #5

merged 11 commits into from
Jan 21, 2019

Conversation

Enkelmann
Copy link
Contributor

Adding the check for CWE-248 into master branch.

@Enkelmann Enkelmann requested a review from tbarabosch January 21, 2019 12:24
Copy link
Contributor

@tbarabosch tbarabosch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this is merged into master, I am going to write an acceptance test with alcotest.

CHANGES.md Outdated
@@ -1,3 +1,9 @@
0.2-dev (2019-XX-XX)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add your CWE as a new feature in 0.2-dev

@@ -1,14 +1,15 @@
# cwe_checker #
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge the file please

@@ -6,116 +6,58 @@ open Yojson.Basic.Util

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge this file as well please



let check_cwe program project tid_map symbol_pairs =
(* Get all subfunctions *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is not needed.

let check_cwe program project tid_map symbol_pairs =
(* Get all subfunctions *)
let subfunctions = Term.enum sub_t program in
(* collect all entry points of the program *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or refactor the functionality ("get_all_cpp_entrypoints") to a new function.

let subfunctions = Term.enum sub_t program in
(* collect all entry points of the program *)
let entry_points = Seq.filter subfunctions ~f:(fun subfn -> Term.has_attr subfn Sub.entry_point) in
(* TODO: The _start entry point calls a libc-function which then calls the main function. Since right now only direct
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to move the TODOs out of the function, right above it. This would improve the readability.

(* search for uncatched exceptions for each entry point, but accumulate the list of already checked functions. *)
(* TODO: Exceptions, that are catched when starting from one entry point, but not from another, are masked this
way. We should check whether this produces a lot of false negatives. *)
let _ = Seq.fold entry_points_with_main ~init:[] ~f:(fun already_checked_functions sub -> find_uncaught_exceptions ~tid_map:tid_map sub already_checked_functions program) in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is fold the right choice here? You do not accumulate results.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, my fault

| Some(tid) -> Some(Tid.name tid)
| None -> None

(* check whether block contains a direct call to a symbol with name symbol_name *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could refactor this function. Extract it as blk_contains_symbol and add it to utils/symbol_utils.ml

@tbarabosch tbarabosch merged commit 3199b67 into master Jan 21, 2019
@tbarabosch tbarabosch deleted the cwe248 branch January 21, 2019 17:12

(* Print the findings to the log *)
let print_uncatched_exception block_tid ~tid_map =
Log_utils.warn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, you could use BAP native logging facilities. Just include Self() and you will get debug, info, warning, and error functions.

val name : string
val version : string

val check_cwe : Bap.Std.program Bap.Std.term -> Bap.Std.project -> Bap.Std.word Bap.Std.Tid.Map.t -> string list list -> unit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Bap.Std interface is designed to be opened (it tries not to pollute the namespace). So once it is open you can easily write the interface in a much more concise and readable way: program term -> project -> word Tid.Map.t -> string list list -> unit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants