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

Fix security issues of the argument parser #1133

Merged
merged 3 commits into from
Jul 4, 2019

Conversation

smehringer
Copy link
Member

Addresses several things of #1101

Best reviewd commit by commit.

@smehringer smehringer requested a review from marehr June 25, 2019 12:01
Copy link
Member

@marehr marehr left a comment

Choose a reason for hiding this comment

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

Thank you for the changes. I have one open question otherwise looks good :)

@@ -88,27 +90,12 @@ class version_checker
#endif
std::smatch versionMatch;

// Ensure version string is not corrupt
if (!version_.empty() && /*regex allows version prefix instead of exact match */
std::regex_search(version_, versionMatch, std::regex("^([[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+).*")))
{
version = versionMatch.str(1); // in case the git revision number is given take only version number
Copy link
Member

Choose a reason for hiding this comment

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

So version = "MALICIOUS CODE"; stays the same, because it does not match the regex and will therefore not be changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

(note the underscore difference)
if version_ == "some malicious code not matching the regex" then the member version will never be set inside the if clause and remains the default "0.0.0".

Is the "zusammenploebbeln" of the command more clear now with the changes?

Copy link
Member

Choose a reason for hiding this comment

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

AH okay, I didn't catch the underscore.

Is the "zusammenploebbeln" of the command more clear now with the changes?

👍

@marehr
Copy link
Member

marehr commented Jul 1, 2019

Hmm jenkins and travis are failing.

home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp: In member function ‘virtual void parser_design_error_app_name_validation_Test::TestBody()’:
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:18:138: error: expected primary-expression before ‘parser’
EXPECT_NO_THROW((argument_parser parser{"test_parser", 1, argv}));
^
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:18:138: error: expected ‘)’ before ‘parser’
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:19:138: error: expected primary-expression before ‘parser’
EXPECT_NO_THROW((argument_parser parser{"test-parser1234_foo", 1, argv}));
^
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:19:138: error: expected ‘)’ before ‘parser’
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:21:189: error: expected primary-expression before ‘parser’
EXPECT_THROW((argument_parser parser{"test parser", 1, argv}), parser_design_error);
^
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:21:189: error: expected ‘)’ before ‘parser’
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:22:189: error: expected primary-expression before ‘parser’
EXPECT_THROW((argument_parser parser{"test;", 1, argv}), parser_design_error);
^
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:22:189: error: expected ‘)’ before ‘parser’
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:23:189: error: expected primary-expression before ‘parser’
EXPECT_THROW((argument_parser parser{";", 1, argv}), parser_design_error);
^
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:23:189: error: expected ‘)’ before ‘parser’
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:24:189: error: expected primary-expression before ‘parser’
EXPECT_THROW((argument_parser parser{"test;bad script:D", 1, argv}), parser_design_error);
^
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:24:189: error: expected ‘)’ before ‘parser’
/home/travis/build/seqan/seqan3/test/unit/argument_parser/argument_parser_design_error_test.cpp:16:18: error: unused variable ‘argv’ [-Werror=unused-variable]
const char * argv[] = {"./argument_parser_test"};
^~~~

{
const char * argv[] = {"./argument_parser_test"};

EXPECT_NO_THROW((argument_parser parser{"test_parser", 1, argv}));
Copy link
Member

Choose a reason for hiding this comment

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

I think you should do this:

Suggested change
EXPECT_NO_THROW((argument_parser parser{"test_parser", 1, argv}));
EXPECT_NO_THROW((argument_parser{"test_parser", 1, argv}));

Copy link
Member

@marehr marehr Jul 1, 2019

Choose a reason for hiding this comment

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

Or

Suggested change
EXPECT_NO_THROW((argument_parser parser{"test_parser", 1, argv}));
EXPECT_NO_THROW(([]()
{
argument_parser parser{"test_parser", 1, argv};
}()));

@smehringer smehringer force-pushed the argument_parser_version_check branch 2 times, most recently from 21d200b to 7fd7ac1 Compare July 2, 2019 08:56
@codecov
Copy link

codecov bot commented Jul 2, 2019

Codecov Report

Merging #1133 into master will increase coverage by <.01%.
The diff coverage is 89.47%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1133      +/-   ##
==========================================
+ Coverage   96.42%   96.43%   +<.01%     
==========================================
  Files         196      196              
  Lines        7757     7761       +4     
==========================================
+ Hits         7480     7484       +4     
  Misses        277      277
Impacted Files Coverage Δ
include/seqan3/argument_parser/auxiliary.hpp 100% <ø> (ø) ⬆️
include/seqan3/argument_parser/argument_parser.hpp 97.39% <100%> (+0.04%) ⬆️
...de/seqan3/argument_parser/detail/version_check.hpp 83.09% <88.23%> (+0.24%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f4e8fd4...ebfee17. Read the comment docs.

@smehringer smehringer requested a review from rrahn July 2, 2019 09:47
Copy link
Contributor

@rrahn rrahn left a comment

Choose a reason for hiding this comment

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

one minor docu comment. Otherwise looks good

@smehringer smehringer force-pushed the argument_parser_version_check branch from 7fd7ac1 to f0c9154 Compare July 2, 2019 13:47
@smehringer smehringer requested a review from rrahn July 2, 2019 13:47
@@ -166,6 +167,10 @@ class argument_parser
* \param[in] argv The command line arguments to parse.
* \param[in] version_check Notify users about app version updates (default true).
*
* \throws seqan3::parser_design_error if the application name contains illegal characters.
*
* The application name must only contain alpha-numeric characters or '_' and '-' (regex: \"^[a-zA-Z0-9_-]+$\").
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* The application name must only contain alpha-numeric characters or '_' and '-' (regex: \"^[a-zA-Z0-9_-]+$\").
* The application name must only contain alpha-numeric characters, '_' or '-', i.e. the following regex must evaluate to true: `\"^[a-zA-Z0-9_-]+$\"`.

Copy link
Contributor

@rrahn rrahn left a comment

Choose a reason for hiding this comment

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

Little update of the comment 💅

@smehringer smehringer force-pushed the argument_parser_version_check branch 2 times, most recently from ac0915a to 3c37f5a Compare July 3, 2019 06:14
@smehringer
Copy link
Member Author

@rrahn Please check the first commit and the last again, I had to rebase after your timeout change was merged.

@h-2 Does /usr/bin/env -i work on FreeBSD/OpenBSD ?

@smehringer smehringer requested a review from rrahn July 3, 2019 11:32
Copy link
Contributor

@rrahn rrahn left a comment

Choose a reason for hiding this comment

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

minor request.

@smehringer smehringer force-pushed the argument_parser_version_check branch from 3c37f5a to ebfee17 Compare July 4, 2019 06:02
@smehringer smehringer requested a review from rrahn July 4, 2019 08:17
Copy link
Contributor

@rrahn rrahn left a comment

Choose a reason for hiding this comment

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

lgtm

@rrahn rrahn merged commit 542b272 into seqan:master Jul 4, 2019
@smehringer smehringer deleted the argument_parser_version_check branch May 29, 2020 05: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.

3 participants