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

Cwe caller #40

Merged
merged 19 commits into from
Dec 4, 2019
Merged

Cwe caller #40

merged 19 commits into from
Dec 4, 2019

Conversation

mellowCS
Copy link
Contributor

@mellowCS mellowCS commented Nov 9, 2019

No description provided.

@mellowCS mellowCS requested a review from Enkelmann November 9, 2019 10:47
Copy link
Contributor

@Enkelmann Enkelmann left a comment

Choose a reason for hiding this comment

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

I wil move the position, where the commandline flags are defined, to the cwe_checker_core library as soon as I find time for it. For the meantime, I added some other comments for you.

src/caller/cwe_checker.ml Outdated Show resolved Hide resolved
src/caller/cwe_checker.ml Outdated Show resolved Hide resolved
src/caller/cwe_checker.ml Outdated Show resolved Hide resolved
Comment on lines 113 to 120
let main () : int =
match Array.length Sys.argv with
| 1 -> Sys.command ("bap " ^ Sys.argv.(1) ^ " --pass=cwe-checker ")
| _ ->
match process_flags with
| None -> 1
| Some [] -> Sys.command ("bap " ^ Sys.argv.(1) ^ " --pass=cwe-checker ")
| Some flags -> Sys.command ("bap " ^ Sys.argv.(1) ^ " --pass=cwe-checker " ^ setup_flags flags)
Copy link
Contributor

Choose a reason for hiding this comment

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

if no flags are given or only the flag --help, we should print a help message. Oh, in that regard we should also implement a --version flag!

src/caller/cwe_checker.mli Outdated Show resolved Hide resolved
@@ -0,0 1,20 @@
(* Removes the nth element of a list *)
Copy link
Contributor

Choose a reason for hiding this comment

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

The comments in .mli files should be documentation comments. Documentation comments start with (** instead of just (* and are parsed by odoc to generate the online documentation.

src/caller/helper_functions.ml Outdated Show resolved Hide resolved
src/caller/helper_functions.ml Outdated Show resolved Hide resolved
Comment on lines 31 to 35
(* Just for type conversion: Returns an empty string if none, else the string *)
let get_default_string (in_option : string option) : string =
match in_option with
| None -> ""
| Some s -> s
Copy link
Contributor

Choose a reason for hiding this comment

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

There is already a method for Options which does the same.

src/caller/helper_functions.mli Outdated Show resolved Hide resolved
@Enkelmann
Copy link
Contributor

The command line flags and parameters are now defined in the Cwe_checker_core.Main module. @mellowCS Could you refactor your code to read them from there? We should also print a custom help message for the --help flag.

…om Cwe_checker_core.Main

- added a function for the help message which is either called when no arguments are given, when the user made an error in the input
  or when the help flag is set.

- removed the json reader function
Added function to get first element of tuple
…and get_second

generalized get_first and get_second to support any input type
Copy link
Contributor

@Enkelmann Enkelmann left a comment

Choose a reason for hiding this comment

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

  • Please delete the now obsolete json file.
  • In your implementation the order of arguments/flags matters, which it should not.
  • We should remove the value checks for parameters from this file, since we already check them in the main module.

Comment on lines 76 to 78
match Sys.is_directory path with
| false -> generate_output_file path ~file:"" ()
| true -> build_path path
Copy link
Contributor

Choose a reason for hiding this comment

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

If the user provides a name of a non-existing file as output path, just pass it through to bap without modification. The filename should not be modified (i.e. no timestamp) in this case to simplify writing scripts with the result from the cwe_checker as input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can the user pass non-existing folders as well? If not, I would check if the given path is valid.

Comment on lines 87 to 88
with
| _ -> raise (NoOutputFileException "No output file provided. If -out flag is set please provide an out file.")
Copy link
Contributor

Choose a reason for hiding this comment

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

This captures the exception out_path can throw and replaces it with another exception. I don't understand why you want to do that here.

Comment on lines 133 to 137
let check_for_help (flags: string list) : string list =
if (Stdlib.List.mem "-help" flags) then (
help ();
remove_string flags "-help"
) else flags
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also check for "--help". Also, the expected behavior for the help flag is to just print the help message and then exit without doing anything else.

@Enkelmann
Copy link
Contributor

Correction: We do want to keep the value checks for parameters here. My mistake. I will move them afterwards to the Main module so that we can use the same checks here and in the Main module.

mellowCS and others added 2 commits December 2, 2019 16:00
…s_params

- changed return types of checks from bool to unit and replaced them with exceptions
- added a check for the binary path
- some more minor type changes
- removed unused functions

- transferred changes of cwe_checker.ml to the mli file respectively

- fixed: binary path's position in command has to be first. -> Now it can be at any position
@Enkelmann
Copy link
Contributor

Looks good. I will add some refactoring of the main module and after that we can merge it.

@Enkelmann Enkelmann merged commit b150586 into master Dec 4, 2019
@Enkelmann Enkelmann deleted the cwe_caller branch December 4, 2019 13:31
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.

2 participants