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
d6b95643
Commit
d6b95643
authored
Sep 09, 2020
by
Enkelmann
Committed by
Enkelmann
Nov 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add file existence validation function
parent
c177eace
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
4 deletions
+24
-4
main.rs
caller/src/main.rs
+24
-4
No files found.
caller/src/main.rs
View file @
d6b95643
use
std
::
process
::
Command
;
use
structopt
::
StructOpt
;
// TODO: Add validation function for `--partial=???` parameter.
// TODO: Add module version printing function
#[derive(Debug,
StructOpt)]
/// Find vulnerable patterns in binary executables
struct
CmdlineArgs
{
/// The path to the binary.
binary
:
String
,
#[structopt(required_unless(
"module-versions"
),
validator(check_file_existence))]
binary
:
Option
<
String
>
,
/// Path to a custom configuration file to use instead of the standard one.
#[structopt(long,
short)]
#[structopt(long,
short
,
validator(check_file_existence)
)]
config
:
Option
<
String
>
,
/// Write the results to a file.
...
...
@@ -39,7 +43,11 @@ struct CmdlineArgs {
fn
main
()
{
let
cmdline_args
=
CmdlineArgs
::
from_args
();
if
let
Some
(
exit_code
)
=
build_bap_command
(
&
cmdline_args
)
.status
()
.unwrap
()
.code
()
{
if
cmdline_args
.module_versions
{
println!
(
"printing module versions"
);
todo!
();
return
;
}
else
if
let
Some
(
exit_code
)
=
build_bap_command
(
&
cmdline_args
)
.status
()
.unwrap
()
.code
()
{
std
::
process
::
exit
(
exit_code
);
}
}
...
...
@@ -47,7 +55,7 @@ fn main() {
/// Build the BAP command corresponding to the given command line arguments.
fn
build_bap_command
(
args
:
&
CmdlineArgs
)
->
Command
{
let
mut
command
=
Command
::
new
(
"bap"
);
command
.arg
(
&
args
.binary
);
command
.arg
(
args
.binary
.as_ref
()
.unwrap
()
);
command
.arg
(
"--pass=cwe-checker"
);
if
let
Some
(
ref
string
)
=
args
.config
{
command
.arg
(
"--cwe-checker-config="
.to_string
()
+
string
);
...
...
@@ -72,3 +80,15 @@ fn build_bap_command(args: &CmdlineArgs) -> Command {
}
command
}
/// Check the existence of a file
fn
check_file_existence
(
file_path
:
String
)
->
Result
<
(),
String
>
{
if
std
::
fs
::
metadata
(
&
file_path
)
.map_err
(|
err
|
format!
(
"{}"
,
err
))
?
.is_file
()
{
Ok
(())
}
else
{
Err
(
format!
(
"{} is not a file."
,
file_path
))
}
}
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