Skip to content

Conversation

@laanwj
Copy link
Member

@laanwj laanwj commented Jun 3, 2015

Change read_string to fail when not the entire input has been consumed. This avoids unexpected, even dangerous behavior (fixes #6223).

The new JSON parser adapted in #6121 also solves this problem so in master this is a temporary fix, but should be backported to older releases.

Also adds tests for the new behavior.

This now errors as expected:

$ src/bitcoin-cli -testnet sendtoaddress msj42CCGruhRsFrGATiUuh25dtxYtnpbTx 1.0dsfs
error: Error parsing JSON:1.0dsfs

Needs backport to 0.10 and 0.11. I don't think older versions are affected, as they did manual parsing of bitcoin-cli arguments.

Note: normally I wouldn't change json_spirit directly as it is an upstream library, but it is going to be dropped anyway, so doing the straightforward fix makes sense

@laanwj
Copy link
Member Author

laanwj commented Jun 3, 2015

Hm this currently breaks other things, looking into it...

It now rejects even valid whitespace at the end, e.g.,

BOOST_CHECK_EQUAL(read_string_test(std::string("1.0 "), value), true);

Must be a better way (there is - json-spirit's info.full, just needs to be bubbled up no, that doesn't work either).

Which leads me into a jungle of boost issues... Looks like this problem :https://svn.boost.org/trac/boost/ticket/1048 "Spirit returns full = false in 1.34 if there is trailing spaces in input"

OK I followed the instructions there and http://thread.gmane.org/gmane.comp.parsers.spirit.general/9839, this should do it.

@laanwj laanwj force-pushed the 2015_06_json_trailing_garbage branch from a4993f7 to 46f92fc Compare June 3, 2015 08:54
@jonasschnelli
Copy link
Contributor

Nice!
utACK. Will test in the next couple of hours.

@maaku
Copy link
Contributor

maaku commented Jun 3, 2015

You should add test cases for the specific case which triggered this in the wild: interpreting an address '1p2pkh...' or '3p2sh...' as a value and getting 1btc / 3btc.

Change `read_string` to fail when not the entire input has been
consumed. This avoids unexpected, even dangerous behavior (fixes bitcoin#6223).

The new JSON parser adapted in bitcoin#6121 also solves this problem so in
master this is a temporary fix, but should be backported to older releases.

Also adds tests for the new behavior.
@laanwj laanwj force-pushed the 2015_06_json_trailing_garbage branch from 46f92fc to 4e157fc Compare June 3, 2015 10:18
@laanwj
Copy link
Member Author

laanwj commented Jun 3, 2015

@maaku OK, added testcases that parsing bitcoin addresses as JSON will fail

@jonasschnelli
Copy link
Contributor

Tested ACK.
Tested specific error behavior after #6223 and testes that nothing got broken by playing around with some rpc commands and ran the -extened version of pull tester.

@laanwj
Copy link
Member Author

laanwj commented Jun 3, 2015

Thanks for testing @jonasschnelli

@laanwj laanwj merged commit 4e157fc into bitcoin:master Jun 3, 2015
laanwj added a commit that referenced this pull request Jun 3, 2015
4e157fc json: fail read_string if string contains trailing garbage (Wladimir J. van der Laan)
laanwj added a commit that referenced this pull request Jun 3, 2015
Change `read_string` to fail when not the entire input has been
consumed. This avoids unexpected, even dangerous behavior (fixes #6223).

The new JSON parser adapted in #6121 also solves this problem so in
master this is a temporary fix, but should be backported to older releases.

Also adds tests for the new behavior.

Github-Pull: #6226
Rebased-From: 4e157fc
laanwj added a commit that referenced this pull request Jun 3, 2015
Change `read_string` to fail when not the entire input has been
consumed. This avoids unexpected, even dangerous behavior (fixes #6223).

The new JSON parser adapted in #6121 also solves this problem so in
master this is a temporary fix, but should be backported to older releases.

Also adds tests for the new behavior.

Github-Pull: #6226
Rebased-From: 4e157fc
@laanwj
Copy link
Member Author

laanwj commented Jun 3, 2015

Backported to 0.11 via a7dcb7eb04357462f65f528a01c37ec59a23ec43
and to 0.10 via 181771b

reddink pushed a commit to reddcoin-project/reddcoin-3.10 that referenced this pull request May 27, 2020
Change `read_string` to fail when not the entire input has been
consumed. This avoids unexpected, even dangerous behavior (fixes bitcoin#6223).

The new JSON parser adapted in bitcoin#6121 also solves this problem so in
master this is a temporary fix, but should be backported to older releases.

Also adds tests for the new behavior.

Github-Pull: bitcoin#6226
Rebased-From: 4e157fc
(cherry picked from commit 181771b)
@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.

RPC validation checks for sendtoaddress

3 participants