-
Notifications
You must be signed in to change notification settings - Fork 36.3k
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
logging: Fix potential use-after-free in LogPrintStr(...) #13148
Conversation
Feel free to take over https://github.com/laanwj/bitcoin/tree/2018_05_logprintf_remove_return_value, which removes the unused and incorrect return value from LogPrintstr and has this commit rebased on top. |
`LogPrintStr` returns the number of characters printed. This number is doubled if both logging to console and logging to file is enabled. As the return value is never used, I've opted to remove it instead of try to fix it. Credit: @laanwj
@laanwj Nice cleanup! Added that commit to this PR. |
utACK 0bd4cd3 |
utACK 0bd4cd3. |
0bd4cd3 logging: remove unused return value from LogPrintStr (practicalswift) 76f344d logging: Fix potential use-after-free in LogPrintStr(...) (practicalswift) Pull request description: Fix potential use-after-free in `LogPrintStr(...)`. `freopen(…)` frees `m_fileout`. Tree-SHA512: ceee1f659c10a21525aa648377afeea0a37016339f5269dea54850ba3b475aa316f4931081655717b65f981598fdc9d79a1e79e55f7084c242eeb7bf372bc4b6
I don't think this patch is really correct -- in the usual failure case where the old file handle is closed, but a new file can't be (re)opened (due to permissions, eg), we'll silently drop the current log message, then start writing any future log messages to the m_msgs_before_open buffer, which will never be cleared. Am I missing something? If I'm not, seems like better behaviour might be something like:
(Would it make sense to do StartShutdown() if logging stops working?) |
Github-Pull: bitcoin#13148 Rebased-From: 76f344d
…trying to re-open (on SIGHUP) 75ea00f Remove unused fsbridge::freopen (practicalswift) cceedbc Don't close old debug log file handle prematurely when trying to re-open (on SIGHUP) (practicalswift) Pull request description: Don't close old debug log file handle prematurely when trying to re-open (on `SIGHUP`). Context: #13148 (comment) Thanks @ajtowns! Tree-SHA512: c436b4286f00fc428b60269b6d6321f435c72c7ccec3c15b2194aac71196529b30f32c2384b418ffe3ed67ba7ee8ec51f4c9c5748e65945697c0437eafcdacd1
Summary: 0bd4cd3 logging: remove unused return value from LogPrintStr (practicalswift) 76f344d logging: Fix potential use-after-free in LogPrintStr(...) (practicalswift) Pull request description: Fix potential use-after-free in `LogPrintStr(...)`. `freopen(…)` frees `m_fileout`. Tree-SHA512: ceee1f659c10a21525aa648377afeea0a37016339f5269dea54850ba3b475aa316f4931081655717b65f981598fdc9d79a1e79e55f7084c242eeb7bf372bc4b6 Backport of Core PR13148 bitcoin/bitcoin#13148 Test Plan: make check Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3976
…trying to re-open (on SIGHUP) Summary: 75ea00f391b742e435c650aae3e827aad913d552 Remove unused fsbridge::freopen (practicalswift) cceedbc4bf1056db17e0adf76d0db45b94777671 Don't close old debug log file handle prematurely when trying to re-open (on SIGHUP) (practicalswift) Pull request description: Don't close old debug log file handle prematurely when trying to re-open (on `SIGHUP`). Context: bitcoin/bitcoin#13148 (comment) Thanks @ajtowns! Tree-SHA512: c436b4286f00fc428b60269b6d6321f435c72c7ccec3c15b2194aac71196529b30f32c2384b418ffe3ed67ba7ee8ec51f4c9c5748e65945697c0437eafcdacd1 Backport of Core PR13159 bitcoin/bitcoin#13159 Depends on D3976 Test Plan: make check ./bitcoind -regtest -daemon cd <path>/.bitcoin/regtest mv debug.log{,.old} touch debug.log; chmod 400 debug.log killall -HUP bitcoind <patch>/bitcoin-abc/build/src/bitcoin-cli -regtest savemempool Verify that the new debug.log file is empty and debug.log.old continued to be written to Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3979
Summary: 0bd4cd3 logging: remove unused return value from LogPrintStr (practicalswift) 76f344d logging: Fix potential use-after-free in LogPrintStr(...) (practicalswift) Pull request description: Fix potential use-after-free in `LogPrintStr(...)`. `freopen(…)` frees `m_fileout`. Tree-SHA512: ceee1f659c10a21525aa648377afeea0a37016339f5269dea54850ba3b475aa316f4931081655717b65f981598fdc9d79a1e79e55f7084c242eeb7bf372bc4b6 Backport of Core PR13148 bitcoin/bitcoin#13148 Test Plan: make check Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3976
…trying to re-open (on SIGHUP) Summary: 75ea00f391b742e435c650aae3e827aad913d552 Remove unused fsbridge::freopen (practicalswift) cceedbc4bf1056db17e0adf76d0db45b94777671 Don't close old debug log file handle prematurely when trying to re-open (on SIGHUP) (practicalswift) Pull request description: Don't close old debug log file handle prematurely when trying to re-open (on `SIGHUP`). Context: bitcoin/bitcoin#13148 (comment) Thanks @ajtowns! Tree-SHA512: c436b4286f00fc428b60269b6d6321f435c72c7ccec3c15b2194aac71196529b30f32c2384b418ffe3ed67ba7ee8ec51f4c9c5748e65945697c0437eafcdacd1 Backport of Core PR13159 bitcoin/bitcoin#13159 Depends on D3976 Test Plan: make check ./bitcoind -regtest -daemon cd <path>/.bitcoin/regtest mv debug.log{,.old} touch debug.log; chmod 400 debug.log killall -HUP bitcoind <patch>/bitcoin-abc/build/src/bitcoin-cli -regtest savemempool Verify that the new debug.log file is empty and debug.log.old continued to be written to Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3979
Summary: 0bd4cd3 logging: remove unused return value from LogPrintStr (practicalswift) 76f344d logging: Fix potential use-after-free in LogPrintStr(...) (practicalswift) Pull request description: Fix potential use-after-free in `LogPrintStr(...)`. `freopen(…)` frees `m_fileout`. Tree-SHA512: ceee1f659c10a21525aa648377afeea0a37016339f5269dea54850ba3b475aa316f4931081655717b65f981598fdc9d79a1e79e55f7084c242eeb7bf372bc4b6 Backport of Core PR13148 bitcoin/bitcoin#13148 Test Plan: make check Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3976
…trying to re-open (on SIGHUP) Summary: 75ea00f391b742e435c650aae3e827aad913d552 Remove unused fsbridge::freopen (practicalswift) cceedbc4bf1056db17e0adf76d0db45b94777671 Don't close old debug log file handle prematurely when trying to re-open (on SIGHUP) (practicalswift) Pull request description: Don't close old debug log file handle prematurely when trying to re-open (on `SIGHUP`). Context: bitcoin/bitcoin#13148 (comment) Thanks @ajtowns! Tree-SHA512: c436b4286f00fc428b60269b6d6321f435c72c7ccec3c15b2194aac71196529b30f32c2384b418ffe3ed67ba7ee8ec51f4c9c5748e65945697c0437eafcdacd1 Backport of Core PR13159 bitcoin/bitcoin#13159 Depends on D3976 Test Plan: make check ./bitcoind -regtest -daemon cd <path>/.bitcoin/regtest mv debug.log{,.old} touch debug.log; chmod 400 debug.log killall -HUP bitcoind <patch>/bitcoin-abc/build/src/bitcoin-cli -regtest savemempool Verify that the new debug.log file is empty and debug.log.old continued to be written to Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc Differential Revision: https://reviews.bitcoinabc.org/D3979
e5476df trivial: enable print_to_file also with print_to_console (random-zebra) bb40861 logging: remove unused return value from LogPrintStr (random-zebra) Pull request description: Bug introduced in b3a1d84: `LogPrintStr` no longer returning the character count, because bitcoin#13148 should have been included in the backport. ACKs for top commit: furszy: Code review ACK e5476df Fuzzbawls: ACK e5476df Tree-SHA512: 51a2e9942a9106a975d45b7f2106ee2426a04d1ec1dc2f1fa8bafd5065205464f61b07e1da0a20fa6ca3237098f18537415bffa1addd5e2736cc22acbc31dd0d
…tStr(...) 0bd4cd3 logging: remove unused return value from LogPrintStr (practicalswift) 76f344d logging: Fix potential use-after-free in LogPrintStr(...) (practicalswift) Pull request description: Fix potential use-after-free in `LogPrintStr(...)`. `freopen(…)` frees `m_fileout`. Tree-SHA512: ceee1f659c10a21525aa648377afeea0a37016339f5269dea54850ba3b475aa316f4931081655717b65f981598fdc9d79a1e79e55f7084c242eeb7bf372bc4b6
…tStr(...) 0bd4cd3 logging: remove unused return value from LogPrintStr (practicalswift) 76f344d logging: Fix potential use-after-free in LogPrintStr(...) (practicalswift) Pull request description: Fix potential use-after-free in `LogPrintStr(...)`. `freopen(…)` frees `m_fileout`. Tree-SHA512: ceee1f659c10a21525aa648377afeea0a37016339f5269dea54850ba3b475aa316f4931081655717b65f981598fdc9d79a1e79e55f7084c242eeb7bf372bc4b6
…tStr(...) 0bd4cd3 logging: remove unused return value from LogPrintStr (practicalswift) 76f344d logging: Fix potential use-after-free in LogPrintStr(...) (practicalswift) Pull request description: Fix potential use-after-free in `LogPrintStr(...)`. `freopen(…)` frees `m_fileout`. Tree-SHA512: ceee1f659c10a21525aa648377afeea0a37016339f5269dea54850ba3b475aa316f4931081655717b65f981598fdc9d79a1e79e55f7084c242eeb7bf372bc4b6
…y when trying to re-open (on SIGHUP) 75ea00f Remove unused fsbridge::freopen (practicalswift) cceedbc Don't close old debug log file handle prematurely when trying to re-open (on SIGHUP) (practicalswift) Pull request description: Don't close old debug log file handle prematurely when trying to re-open (on `SIGHUP`). Context: bitcoin#13148 (comment) Thanks @ajtowns! Tree-SHA512: c436b4286f00fc428b60269b6d6321f435c72c7ccec3c15b2194aac71196529b30f32c2384b418ffe3ed67ba7ee8ec51f4c9c5748e65945697c0437eafcdacd1 # Conflicts: # src/logging.cpp
…y when trying to re-open (on SIGHUP) 75ea00f Remove unused fsbridge::freopen (practicalswift) cceedbc Don't close old debug log file handle prematurely when trying to re-open (on SIGHUP) (practicalswift) Pull request description: Don't close old debug log file handle prematurely when trying to re-open (on `SIGHUP`). Context: bitcoin#13148 (comment) Thanks @ajtowns! Tree-SHA512: c436b4286f00fc428b60269b6d6321f435c72c7ccec3c15b2194aac71196529b30f32c2384b418ffe3ed67ba7ee8ec51f4c9c5748e65945697c0437eafcdacd1 # Conflicts: # src/logging.cpp
…y when trying to re-open (on SIGHUP) 75ea00f Remove unused fsbridge::freopen (practicalswift) cceedbc Don't close old debug log file handle prematurely when trying to re-open (on SIGHUP) (practicalswift) Pull request description: Don't close old debug log file handle prematurely when trying to re-open (on `SIGHUP`). Context: bitcoin#13148 (comment) Thanks @ajtowns! Tree-SHA512: c436b4286f00fc428b60269b6d6321f435c72c7ccec3c15b2194aac71196529b30f32c2384b418ffe3ed67ba7ee8ec51f4c9c5748e65945697c0437eafcdacd1 # Conflicts: # src/logging.cpp
…tStr(...) 0bd4cd3 logging: remove unused return value from LogPrintStr (practicalswift) 76f344d logging: Fix potential use-after-free in LogPrintStr(...) (practicalswift) Pull request description: Fix potential use-after-free in `LogPrintStr(...)`. `freopen(…)` frees `m_fileout`. Tree-SHA512: ceee1f659c10a21525aa648377afeea0a37016339f5269dea54850ba3b475aa316f4931081655717b65f981598fdc9d79a1e79e55f7084c242eeb7bf372bc4b6
Fix potential use-after-free in
LogPrintStr(...)
.freopen(…)
freesm_fileout
.