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

Quit testssl.sh on all command line errors #1871

Merged
merged 1 commit into from
Dec 24, 2023

Conversation

dcooper16
Copy link
Contributor

@dcooper16 dcooper16 commented Apr 8, 2021

As suggested in #1844, this PR changes testssl.sh so that the parent process quits immediately if there is an error in the command line for one of the child processes.

Currently, a signal is sent to the parent process to quit if the child process encounters an error and calls help(). But sometimes parse_cmd_line() just prints an error message and calls fatal() rather than help(), in which case the parent process does not stop. This PR addresses the issue by creating a new function, fatal_cmd_line(), which is almost the same as fatal(), but additionally sends a signal to the parent indicating that the parent should stop. This PR also changes calls to fatal() to calls to fatal_cmd_line() if json_header(), csv_header(), html_header(), or prepare_logging() encounter a problem. The same is done if prettyprint_local() with the command-line option provided for it.

There may be other places in which it would be appropriate to call fatal_cmd_line() rather than fatal() (e.g., in parse_hn_port() or check_proxy()), but those changes are not made in this PR.

Another issue that this PR addresses is that sometimes when parse_cmd_line() prints an error messsage and then calls help() the error message is send to stderr and other times it is sent to stdout. This PR sends all of these error messages to stderr.

@dcooper16
Copy link
Contributor Author

When working on this PR I noticed that the parse_cmd_line() parses the -V (or --local) option within the while loop rather than at the beginning where the --help and --banner options are handled, even though -V is also a standalone option. Is there a reason for this?

@drwetter
Copy link
Owner

drwetter commented Apr 9, 2021

even though -V is also a standalone option. Is there a reason for this?

It's not a standalone option as one can supply a pattern. However we need to question the usefulness of this legacy implementation as it only lists the ciphers from OpenSSL:

image

@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 4 times, most recently from e6acf7f to 8ce04ff Compare May 17, 2021 14:33
@drwetter
Copy link
Owner

drwetter commented Jun 7, 2021

Argh. Sorry, David, to let this hang for a longer time. It seems my comment I thought to have posted wasn't. My point was that (besides honoring your work) it is not clear to me whether this PR does always send a signal to the parent when one host has a problem -- independent on whether the output is in one file or multiple, see my comment #1844 (comment) .

If I don't miss anything we maybe should not default to this behavior. Maybe a cmdline flag would do good here like ~ --term-on-error of a logic which does this automatically if the output is JSON and if the output is supposed to be in one file.

@dcooper16
Copy link
Contributor Author

If you don't think this PR makes sense, then it's fine to just close it. However, at the moment testssl.sh's behavior is inconsistent with respect to command line errors. For example, if the file provided to the --file option contains:

--protocols 127.0.0.1
--nodns=minimum 127.0.0.1
--protocols 127.0.0.1:631

then an error message will be printed for the second line, but the tests for the other two lines will run. On the other hand, if the file provided to the --file option contains:

--protocols 127.0.0.1
--color 4 127.0.0.1
--protocols 127.0.0.1:631

then testssl.sh will stop as soon as the second line is parsed. The third line is never run, and in parallel mode the test from the first line is stopped before it completes.

The difference is that parse_cmd_line() calls fatal() when an invalid option is provided for --nodns, but calls help() when an invalid option is provided for --color. fatal() just stops the child process. help() sends a USR1 signal to the parent, which causes the parent to terminate all child processes and then stop itself.

@drwetter
Copy link
Owner

ok, thanks for your heads up.

@drwetter drwetter self-assigned this Jun 15, 2021
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 2 times, most recently from 588a216 to 71a48b8 Compare August 2, 2021 15:25
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 2 times, most recently from f7edb3d to 9669da4 Compare August 9, 2021 17:21
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 2 times, most recently from 8ec0eb4 to af7b05e Compare September 27, 2021 19:11
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 2 times, most recently from de39516 to 8eee4cc Compare October 4, 2021 14:32
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 5 times, most recently from 43925bd to f910c31 Compare October 27, 2021 11:26
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 2 times, most recently from c7bfde8 to 11328fa Compare October 29, 2021 11:00
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 4 times, most recently from 8a9239c to 32383e6 Compare February 8, 2023 19:49
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 2 times, most recently from c10cf2a to ccd9fe0 Compare March 20, 2023 14:33
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 3 times, most recently from 4753687 to bb9ee99 Compare April 3, 2023 14:16
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 2 times, most recently from ded28c1 to e6b0655 Compare May 23, 2023 16:54
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 2 times, most recently from af5f7d0 to 761ad3b Compare August 28, 2023 21:36
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 3 times, most recently from 6ad3e67 to 4723835 Compare September 11, 2023 12:39
@dcooper16 dcooper16 force-pushed the quit_on_cmd_line_errors branch 2 times, most recently from a4888d5 to bc5d192 Compare October 10, 2023 21:12
@polarathene
Copy link
Contributor

Is the rebasing automated? Is there a blocker to merging /resolving this?

Just curious as I regularly get notifications from the activity, but it's unclear what the status is?

Looks like the decision was to opt-in to this added logic via an option? But there doesn't seem to be any activity towards that.

@drwetter
Copy link
Owner

Yeah, that one is on me, sorry. I had some concerns in the beginning but as time passed by I forgot what it was and wasn't able to put this fwd in my queue. That will be solved for release,

As suggested in drwetter#1844, this commit changes testssl.sh so that the parent process quits immediately if there is an error in the command line for one of the child processes.

Currently, a signal is sent to the parent process to quit if the child process encounters an error and calls help(), but sometimes parse_cmd_line() just prints an error message and calls fatal() rather than help(), in which case the parent process does not stop. This commit addresses the issue by creating a new function, fatal_cmd_line(), which is almost the same as fatal(), but additionally sends a signal to the parent indicating that the parent should stop. This commit also changes calls to fatal() to calls to fatal_cmd_line() if json_header(), csv_header(), html_header(), or prepare_logging() encounter a problem. The same is done if prettyprint_local() with the command-line option provided for it.

There may be other places in which it would be appropriate to call fatal_cmd_line() rather than fatal() (e.g., in parse_hn_port() or check_proxy()), but those changes are not made in this commit.
@drwetter drwetter merged commit 3f9cc7b into drwetter:3.2 Dec 24, 2023
2 checks passed
@drwetter
Copy link
Owner

Thanks, David. Sorry to keep this pending for a long time.

@dcooper16 dcooper16 deleted the quit_on_cmd_line_errors branch January 3, 2024 15:01
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.

None yet

3 participants