util: Fix UB in SetStdinEcho when ENOTTY#34597
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
l0rinc
left a comment
There was a problem hiding this comment.
concept ACK
Does this enable the removal of
bitcoin/test/sanitizer_suppressions/ubsan
Line 58 in d7c9d6c
|
No, that is just a harmless warning. I guess I can refactor it a bit while touching this... |
|
Pushed that as well. Needs compilation with the integer sanitizer ( |
| // https://stackoverflow.com/questions/1413445/reading-a-password-from-stdcin | ||
| void SetStdinEcho(bool enable) | ||
| { | ||
| if (!StdinTerminal()) { |
There was a problem hiding this comment.
Since this is now checked here, should failure below log an error? (Maybe visibly so the user knows to expect echo?)
There was a problem hiding this comment.
I don't think an error can happen, so this seems a bit too much effort for basically dead/untested code
There was a problem hiding this comment.
actually, done with a simple fputs and a string literal for each case
| } | ||
| if (!enable) { | ||
| tty.c_lflag &= ~ECHO; | ||
| tty.c_lflag &= static_cast<decltype(tty.c_lflag)>(~ECHO); |
There was a problem hiding this comment.
Probably should do the case before the bitwise negation?
There was a problem hiding this comment.
I don't think it matters here, because everything will be compiled down to the same executable anyway and this is just to silence a harmless ubsan warning.
…r warning This refactor does not change any behavior, except for the integer sanitizer warning. Can be tested via: UBSAN_OPTIONS="suppressions=$(pwd)/test/sanitizer_suppressions/ubsan:print_stacktrace=1:halt_on_error=1:report_error_type=1" ./bld-cmake/bin/bitcoin-cli -stdinrpcpass uptime
faff796 to
fa6af85
Compare
|
ACK fa6af85 |
sedited
left a comment
There was a problem hiding this comment.
ACK fa6af85
Was thinking why we don't just throw on these errors, but I think printing something to stderr is the correct thing to do, and introducing exceptions was discussed in the original PR: #13716 (comment) .
I think that was referring to the |
|
lightly tested code review ACK fa6af85 Thanks for fixing these and removing the suppressions - they always make me nervous. |
Github-Pull: bitcoin#34597 Rebased-From: fa69297
…r warning This refactor does not change any behavior, except for the integer sanitizer warning. Can be tested via: UBSAN_OPTIONS="suppressions=$(pwd)/test/sanitizer_suppressions/ubsan:print_stacktrace=1:halt_on_error=1:report_error_type=1" ./bld-cmake/bin/bitcoin-cli -stdinrpcpass uptime Github-Pull: bitcoin#34597 Rebased-From: fa6af85
|
Backported to |
Github-Pull: bitcoin#34597 Rebased-From: fa69297
…r warning This refactor does not change any behavior, except for the integer sanitizer warning. Can be tested via: UBSAN_OPTIONS="suppressions=$(pwd)/test/sanitizer_suppressions/ubsan:print_stacktrace=1:halt_on_error=1:report_error_type=1" ./bld-cmake/bin/bitcoin-cli -stdinrpcpass uptime Github-Pull: bitcoin#34597 Rebased-From: fa6af85
49a777d doc: update release notes for v30.x (fanquake) 0f9e08f doc: update build guides pre v31 (fanquake) 597ac36 doc: Fix `fee` field in `getblock` RPC result (nervana21) 47ed306 depends: Allow building Qt packages after interruption (Hennadii Stepanov) d221d1c psbt: validate pubkeys in MuSig2 pubnonce/partial sig deserialization (tboy1337) e1210ac doc: Improve dependencies.md IPC documentation (Ryan Ofsky) c17a5cd test: Add missing timeout_factor to zmq socket (MarcoFalke) 3042509 netif: fix compilation warning in QueryDefaultGatewayImpl() (MarcoFalke) 475a5b0 refactor: Use static_cast<decltype(...)> to suppress integer sanitizer warning (MarcoFalke) 7220ee3 util: Fix UB in SetStdinEcho when ENOTTY (MarcoFalke) Pull request description: Backports: * #34093 * #34219 * #34597 * #34690 * #34702 * #34706 * #34713 * #34789 ACKs for top commit: marcofleon: ACK 49a777d Tree-SHA512: b4ce54860b7306b22de75bb093ad574110875253e4ea3ca96a736809c8291dea1144a617c8791f36618d8e367022709ba5cf84ca0e450ef6d76394ab80f22e2f
The call to
tcgetattrmay fail withENOTTY, leaving the struct possibly uninitialized (UB).Fix this UB by returning early when
isattyfails, or whentcgetattrfails. (Same for Windows)This can be tested by a command that fails valgrind before the change and passes after: