-
Notifications
You must be signed in to change notification settings - Fork 12
Handle closed standard input gracefully #27
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
Conversation
This doesn't quite work, as stdin is used in more than just the lines this PR hardens:
For |
I gave up on |
0b2b082
to
49993e2
Compare
The failing tests are unrelated to this PR. It mentions |
Ready for review @ArrayBolt3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly good, only a few things I noticed that could use changed.
usr/bin/-
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file was created on accident.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
if stdin is not None: | ||
for untrusted_text in stdin: | ||
untrusted_text_list.append(untrusted_text) | ||
if stdin is not None and len(argv) == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to always take the else
branch here if stdin is None
? I don't think we need the stdin check here. The tests also seem to pass for me if I remove the stdin check here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
run-tests
Outdated
stdin_utils=(stcat stcatn sttee stsponge) | ||
utils=(stprint stecho "${stdin_utils[@]}") | ||
cd "${git_toplevel}/usr/bin" | ||
"${black[@]}" -- "${utils[@]}" | ||
"${pylint[@]}" -- "${utils[@]}" | ||
for file in "${utils[@]}"; do | ||
"${mypy[@]}" -- "${file}" | ||
done | ||
|
||
for util in "${stdin_utils[@]}"; do | ||
./"${util}" <&- | ||
./"${util}" - <&- | ||
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If either of sttee
or stsponge
are called as ./"${util}" - <&-
, they will create a file named -
. When running the tests, that ends up creating usr/bin/-
, which is probably how that file got into thie PR. Can we divide stdin_utils
a bit more so that we can skip the -
argument for those two utils?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
utils=(stprint stecho stcat stcatn sttee stsponge) | ||
stdin_utils_to_stdout=(stcat stcatn) | ||
stdin_utils_to_file=(sttee stsponge) | ||
utils=(stprint stecho "${stdin_utils[@]}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utils=(stprint stecho "${stdin_utils[@]}") | |
utils=(stprint stecho "${stdin_utils_to_stdout[@]}" "${stdin_utils_to_file[@]}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than this change, I think this is ready to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! @adrelanos Ready to merge.
This pull request changes...
Changes
Ignore NoneType stdin.
Mandatory Checklist
Terms of Service, Privacy Policy, Cookie Policy, E-Sign Consent, DMCA, Imprint
Optional Checklist
The following items are optional but might be requested in certain cases.
Fixes #26