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
4 years ago
by
Enkelmann
Committed by
Enkelmann
4 years ago
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
std
::
process
::
Command
;
use
structopt
::
StructOpt
;
use
structopt
::
StructOpt
;
// TODO: Add validation function for `--partial=???` parameter.
// TODO: Add module version printing function
#[derive(Debug,
StructOpt)]
#[derive(Debug,
StructOpt)]
/// Find vulnerable patterns in binary executables
/// Find vulnerable patterns in binary executables
struct
CmdlineArgs
{
struct
CmdlineArgs
{
/// The path to the binary.
/// 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.
/// 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
>
,
config
:
Option
<
String
>
,
/// Write the results to a file.
/// Write the results to a file.
...
@@ -39,7 +43,11 @@ struct CmdlineArgs {
...
@@ -39,7 +43,11 @@ struct CmdlineArgs {
fn
main
()
{
fn
main
()
{
let
cmdline_args
=
CmdlineArgs
::
from_args
();
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
);
std
::
process
::
exit
(
exit_code
);
}
}
}
}
...
@@ -47,7 +55,7 @@ fn main() {
...
@@ -47,7 +55,7 @@ fn main() {
/// Build the BAP command corresponding to the given command line arguments.
/// Build the BAP command corresponding to the given command line arguments.
fn
build_bap_command
(
args
:
&
CmdlineArgs
)
->
Command
{
fn
build_bap_command
(
args
:
&
CmdlineArgs
)
->
Command
{
let
mut
command
=
Command
::
new
(
"bap"
);
let
mut
command
=
Command
::
new
(
"bap"
);
command
.arg
(
&
args
.binary
);
command
.arg
(
args
.binary
.as_ref
()
.unwrap
()
);
command
.arg
(
"--pass=cwe-checker"
);
command
.arg
(
"--pass=cwe-checker"
);
if
let
Some
(
ref
string
)
=
args
.config
{
if
let
Some
(
ref
string
)
=
args
.config
{
command
.arg
(
"--cwe-checker-config="
.to_string
()
+
string
);
command
.arg
(
"--cwe-checker-config="
.to_string
()
+
string
);
...
@@ -72,3 +80,15 @@ fn build_bap_command(args: &CmdlineArgs) -> Command {
...
@@ -72,3 +80,15 @@ fn build_bap_command(args: &CmdlineArgs) -> Command {
}
}
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
))
}
}
This diff is collapsed.
Click to expand it.
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