Skip to content

Conversation

@Empact
Copy link
Contributor

@Empact Empact commented Jun 8, 2018

This consolidates separate hash parsing functions from
rpc/server.cpp, rest.cpp, and core_read.cpp into a low-level
parser ParseHashStr in core_read.cpp, and an rpc-level ParseHash in rpc/server.cpp.

Note the rpc parser calls through to the core_io parser.

Behavior changes are:

  • Hashes are consistently validated to 64 characters, the expected
    length for 256 bits hexidecimal. Because all newly-tested calls
    were against txids or blockhashes, this is safe.
  • prioritisetransaction now throws an RPC_INVALID_PARAMETER rather
    than std::runtime_error on bad hash. This is in the context of rpc,
    so seems more appropriate.
  • A bunch of calls that did not error meaningfully on bad hashes now do.

@Empact Empact force-pushed the parse-hash branch 4 times, most recently from 4af3e97 to c1b848f Compare June 8, 2018 11:05
The one existing call in bitcoin-tx already validates the call will
pass via checkObject.
@Empact Empact force-pushed the parse-hash branch 9 times, most recently from 40dbbf3 to 5048be5 Compare June 8, 2018 12:27
Empact added 2 commits June 8, 2018 05:30
This consolidates separate hash parsing functions from
rpc/server.cpp, rest.cpp, and core_read.cpp into a low-level
parser in core_read.cpp, and an rpc-level parser in rpc/server.cpp.

Note the rpc parser calls through to the core_io parser.

Behavior changes are:
* Hashes are consistently validated to 64 characters, the expected
  length for 256 bits hexidecimal. Because all newly-tested calls
  were against txids, this is safe.
* prioritisetransaction now throws an RPC_INVALID_PARAMETER rather
  than std::runtime_error on bad hash. This is in the context of rpc,
  so seems more appropriate.
These calls were previously unvalidated. As of this change, only
hashes in test and qt are unvalidated.
@Empact
Copy link
Contributor Author

Empact commented Jun 8, 2018

TODO: add tests for the new rpc errors on the various calls that now consistently validate input

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 8, 2018

Note to reviewers: 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.

@DrahtBot DrahtBot mentioned this pull request Jun 8, 2018
@maflcko
Copy link
Member

maflcko commented Jun 8, 2018

Concept ACK.

@Empact
Copy link
Contributor Author

Empact commented Jun 8, 2018

Going to split this up to ease review.

@Empact Empact closed this Jun 8, 2018
maflcko pushed a commit that referenced this pull request Jun 15, 2018
abd2678 Drop ParseHashUV in favor of calling ParseHashStr (Ben Woosley)

Pull request description:

  The one existing call already validates `get_str` will pass via `checkObject`:
  https://github.com/bitcoin/bitcoin/pull/13422/files#diff-8fe4d6985ee4acf8bfc1ed8db1e83cb5L586

  Split from #13420

Tree-SHA512: 35dfa8c28d0c3ceac7a6de7f4eb4a44d912f4c31f5d21c9438f899566ca2b34851f1a58c3417355e55d0c33abb97385f4a47e034bfc8e3cdbbf5f73813ca0582
@Empact Empact deleted the parse-hash branch July 2, 2018 02:58
maflcko pushed a commit that referenced this pull request Sep 24, 2018
…ing in rpc calls

5eb20f8 Consistently use ParseHashV to validate hash inputs in rpc (Ben Woosley)

Pull request description:

  ParseHashV validates the length and encoding of the string and throws
  an informative RPC error on failure, which is as good or better than
  these alternative calls.

  Note I switched ParseHashV to check string length first, because
  IsHex tests that the length is even, and an error like:
  "must be of length 64 (not 63, for X)" is much more informative than
  "must be hexadecimal string (not X)" in that case.

  Split from #13420

Tree-SHA512: f0786b41c0d7793ff76e4b2bb35547873070bbf7561d510029e8edb93f59176277efcd4d183b3185532ea69fc0bbbf3dbe9e19362e8017007ae9d51266cd78ae
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 7, 2020
abd2678 Drop ParseHashUV in favor of calling ParseHashStr (Ben Woosley)

Pull request description:

  The one existing call already validates `get_str` will pass via `checkObject`:
  https://github.com/bitcoin/bitcoin/pull/13422/files#diff-8fe4d6985ee4acf8bfc1ed8db1e83cb5L586

  Split from bitcoin#13420

Tree-SHA512: 35dfa8c28d0c3ceac7a6de7f4eb4a44d912f4c31f5d21c9438f899566ca2b34851f1a58c3417355e55d0c33abb97385f4a47e034bfc8e3cdbbf5f73813ca0582
pravblockc pushed a commit to pravblockc/dash that referenced this pull request Jul 23, 2021
…nd encoding in rpc calls

5eb20f8 Consistently use ParseHashV to validate hash inputs in rpc (Ben Woosley)

Pull request description:

  ParseHashV validates the length and encoding of the string and throws
  an informative RPC error on failure, which is as good or better than
  these alternative calls.

  Note I switched ParseHashV to check string length first, because
  IsHex tests that the length is even, and an error like:
  "must be of length 64 (not 63, for X)" is much more informative than
  "must be hexadecimal string (not X)" in that case.

  Split from bitcoin#13420

Tree-SHA512: f0786b41c0d7793ff76e4b2bb35547873070bbf7561d510029e8edb93f59176277efcd4d183b3185532ea69fc0bbbf3dbe9e19362e8017007ae9d51266cd78ae
@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.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants