Skip to content

Conversation

@achow101
Copy link
Member

@achow101 achow101 commented Mar 23, 2017

Ensures that there is an item on the rpcconsole stack before adding something to the current stack so that a segmentation fault does not occur.

Currently Bitcoin Core will just crash if there happens to be a newline somewhere in the command followed by some non-whitespace characters which are followed by a space. This causes a segfault by attempting to get the current stack from the empty stack vector. This fix ensures that that current stack always exists so that the segfault does not happen.

The crashing behavior can be tested by using this command in the rpcconsole:

decoderawtransaction 01000000 03e7a6f3 a93af3ae 49518cbf 8600b799 b04a8b8a ae5145f0 b25df06e 
  175d472a a

(copy and paste it as one line)

@fanquake fanquake added this to the 0.14.1 milestone Mar 23, 2017
@fanquake
Copy link
Member

Confirmed that Core does segfault when using the above command in the rpcconsole, and that it no longer happens with the PR'd fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

space after if please and left brace on the same line (or maybe one line if without braces - see https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md).

@paveljanik
Copy link
Contributor

Concept ACK

@achow101 achow101 force-pushed the fix-rpcconsole-empty-stack branch from f9c9ef7 to f3fa05a Compare March 23, 2017 14:50
@jonasschnelli
Copy link
Contributor

jonasschnelli commented Mar 24, 2017

Thanks for pointing this out.
Hmm... is there a reason to allow newlines in the command-line?
I don't think so.
Maybe this fix is more robust:

diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp
index 7a0d0b3..c2f6434 100644
--- a/src/qt/rpcconsole.cpp
+++ b/src/qt/rpcconsole.cpp
@@ -190,6 +190,7 @@ bool RPCConsole::RPCParseCommandLine(std::string &strResult, const std::string &
     };
 
     std::string strCommandTerminated = strCommand;
+    std::replace(strCommandTerminated.begin(),strCommandTerminated.end(),'\n',' ');
     if (strCommandTerminated.back() != '\n')
         strCommandTerminated += "\n";
     for (chpos = 0; chpos < strCommandTerminated.size(); ++chpos)

@achow101 achow101 changed the title [RPC] Ensure an item exists on the rpcconsole stack before adding [Qt] Ensure an item exists on the rpcconsole stack before adding Mar 24, 2017
@achow101
Copy link
Member Author

@jonasschnelli The segfault bug happens with more than just a newline in the command. It also happens if an end parenthesis ) is also in the command without a start parenthesis ( before it.

Copy link
Member

Choose a reason for hiding this comment

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

Nit: space after if please.

@sipa
Copy link
Member

sipa commented Mar 24, 2017

utACK, with nit.

Ensures that there is an item on the rpcconsole stack before adding something to the current stack so that a segmentation fault does not occur.
@achow101 achow101 force-pushed the fix-rpcconsole-empty-stack branch from f3fa05a to 4df76e2 Compare March 25, 2017 05:44
@jonasschnelli
Copy link
Contributor

Thanks @achow101 for clarification.
Tested ACK 4df76e2

@jonasschnelli
Copy link
Contributor

Needs backport.

@jonasschnelli jonasschnelli merged commit 4df76e2 into bitcoin:master Mar 27, 2017
jonasschnelli added a commit that referenced this pull request Mar 27, 2017
…re adding

4df76e2 Ensure an item exists on the rpcconsole stack before adding (Andrew Chow)

Tree-SHA512: f3fd5e70da186949aff794f6e2ba122da2145331212dcc5e0595285bee9dc3aa6b400b15e8eeec4476099965b74f46c4ef80f8ed1e05d490580167b002b9a5e7
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Mar 27, 2017
Ensures that there is an item on the rpcconsole stack before adding something to the current stack so that a segmentation fault does not occur.

Github-Pull: bitcoin#10060
Rebased-From: 4df76e2
@achow101 achow101 deleted the fix-rpcconsole-empty-stack branch April 5, 2017 14:30
codablock pushed a commit to codablock/dash that referenced this pull request Jan 26, 2018
…ck before adding

4df76e2 Ensure an item exists on the rpcconsole stack before adding (Andrew Chow)

Tree-SHA512: f3fd5e70da186949aff794f6e2ba122da2145331212dcc5e0595285bee9dc3aa6b400b15e8eeec4476099965b74f46c4ef80f8ed1e05d490580167b002b9a5e7
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
…ck before adding

4df76e2 Ensure an item exists on the rpcconsole stack before adding (Andrew Chow)

Tree-SHA512: f3fd5e70da186949aff794f6e2ba122da2145331212dcc5e0595285bee9dc3aa6b400b15e8eeec4476099965b74f46c4ef80f8ed1e05d490580167b002b9a5e7
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Feb 27, 2019
…ck before adding

4df76e2 Ensure an item exists on the rpcconsole stack before adding (Andrew Chow)

Tree-SHA512: f3fd5e70da186949aff794f6e2ba122da2145331212dcc5e0595285bee9dc3aa6b400b15e8eeec4476099965b74f46c4ef80f8ed1e05d490580167b002b9a5e7
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants