-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Consolidate redundant implementations of ParseHashStr #14307
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
Conversation
maflcko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK. Looks like the new parse helper will reject strings that are hex but not exactly 64 chars. Could add a test that fails with this change, but passes without?
src/core_read.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could keep the name strHex and result to minimize the diff?
src/core_read.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Redundant parentheses around strReq.size() != 64 :-)
src/bitcoin-tx.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is unchanged from the previous version, but could there be circumstances where this opens up for log file injection? Safer not to echo the input?
c76c7ad to
dc95535
Compare
src/rpc/mining.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is unchanged from the previous version, but could there be circumstances where this opens up for log file injection? Safer not to echo the input?
|
Concept ACK Thanks for taking on this issue. Closing #14288. |
e063b15 to
a85bbe9
Compare
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. |
a85bbe9 to
c5f066e
Compare
|
Rebased for #13424 |
c5f066e to
0b5791e
Compare
|
Converted one parse from |
src/core_read.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Redundant parentheses around strHex.size() != 64 :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could go either way but I like explicit precedence to guide the eye.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps swap the two boolean conditions? If the condition strHex.size() is false then the function can return without having to evaluate the condition IsHex(strHex)
if ((strHex.size() != 64) || !IsHex(strHex)) return false;
src/bitcoin-tx.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is unchanged from the previous version, but could there be circumstances where this opens up for log file injection? Safer not to echo the input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This had been changed so I switched it back.
|
What about adding |
c60cfb7 to
f78c166
Compare
|
I like |
f78c166 to
909a8f6
Compare
|
@MarcoFalke added tests, only two of them fail before this change because of existing checks:
|
l2a5b1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 909a8f6
Nice improvement!
src/core_io.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can document bool ParseHashStr(const std::string& strHex, uint256& result) and specify the pre-condition that the strHex argument must be a hexadecimal string with a length of 64 bytes.
src/core_read.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps swap the two boolean conditions? If the condition strHex.size() is false then the function can return without having to evaluate the condition IsHex(strHex)
if ((strHex.size() != 64) || !IsHex(strHex)) return false;This change: * adds a length check to ParseHashStr, appropriate given its use to populate a 256-bit number from a hex str. * allows the caller to handle the failure, which allows for the more appropriate JSONRPCError on failure in prioritisetransaction rpc
909a8f6 to
9c5af58
Compare
|
Switched the condition and added docs. |
|
utACK 9c5af58 |
| * @param[out] result the result of the parasing | ||
| * @returns true if successful, false if not | ||
| * | ||
| * @see ParseHashV for an RPC-oriented version of this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ParseHashV could use ParseHashStr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to do that as a follow-up.
|
utACK 9c5af58. |
|
utACK 9c5af58 |
9c5af58 Consolidate redundant implementations of ParseHashStr (Ben Woosley) Pull request description: This change: * adds a length check to all calls to `ParseHashStr`, appropriate given its use to populate a 256-bit number from a hex str * allows the caller to handle the failure, which allows for the more appropriate `JSONRPCError` on failure in `prioritisetransaction` rpc Relative to #14288 Tree-SHA512: baa791147e5ceb3c30c70df3981aaf807bf7d4a90a0be3625540b59aa4b9a9d303a452bfef18bf167cbb833ef9591b4ef5948bf4a1ce67b421d804ae8d20ea53
Summary:
9c5af58d51 Consolidate redundant implementations of ParseHashStr (Ben Woosley)
Pull request description:
This change:
* adds a length check to all calls to `ParseHashStr`, appropriate given its use to populate
a 256-bit number from a hex str
* allows the caller to handle the failure, which allows for the more
appropriate `JSONRPCError` on failure in `prioritisetransaction` rpc
Relative to #14288
Tree-SHA512: baa791147e5ceb3c30c70df3981aaf807bf7d4a90a0be3625540b59aa4b9a9d303a452bfef18bf167cbb833ef9591b4ef5948bf4a1ce67b421d804ae8d20ea53
Backport of Core [[bitcoin/bitcoin#14307 | PR14307]]
bitcoin/bitcoin#14307
Depends on D5294
Test Plan:
ninja check
ninja check-functional
Reviewers: O1 Bitcoin ABC, #bitcoin_abc, Fabien
Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D5295
Summary:
9c5af58d51 Consolidate redundant implementations of ParseHashStr (Ben Woosley)
Pull request description:
This change:
* adds a length check to all calls to `ParseHashStr`, appropriate given its use to populate
a 256-bit number from a hex str
* allows the caller to handle the failure, which allows for the more
appropriate `JSONRPCError` on failure in `prioritisetransaction` rpc
Relative to #14288
Tree-SHA512: baa791147e5ceb3c30c70df3981aaf807bf7d4a90a0be3625540b59aa4b9a9d303a452bfef18bf167cbb833ef9591b4ef5948bf4a1ce67b421d804ae8d20ea53
Backport of Core [[bitcoin/bitcoin#14307 | PR14307]]
bitcoin/bitcoin#14307
Depends on D5294
Test Plan:
ninja check
ninja check-functional
Reviewers: O1 Bitcoin ABC, #bitcoin_abc, Fabien
Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D5295
…ashStr 9c5af58 Consolidate redundant implementations of ParseHashStr (Ben Woosley) Pull request description: This change: * adds a length check to all calls to `ParseHashStr`, appropriate given its use to populate a 256-bit number from a hex str * allows the caller to handle the failure, which allows for the more appropriate `JSONRPCError` on failure in `prioritisetransaction` rpc Relative to bitcoin#14288 Tree-SHA512: baa791147e5ceb3c30c70df3981aaf807bf7d4a90a0be3625540b59aa4b9a9d303a452bfef18bf167cbb833ef9591b4ef5948bf4a1ce67b421d804ae8d20ea53
…shStr 9c5af58 Consolidate redundant implementations of ParseHashStr (Ben Woosley) Pull request description: This change: * adds a length check to all calls to `ParseHashStr`, appropriate given its use to populate a 256-bit number from a hex str * allows the caller to handle the failure, which allows for the more appropriate `JSONRPCError` on failure in `prioritisetransaction` rpc Relative to bitcoin#14288 Tree-SHA512: baa791147e5ceb3c30c70df3981aaf807bf7d4a90a0be3625540b59aa4b9a9d303a452bfef18bf167cbb833ef9591b4ef5948bf4a1ce67b421d804ae8d20ea53
This change:
ParseHashStr, appropriate given its use to populatea 256-bit number from a hex str
appropriate
JSONRPCErroron failure inprioritisetransactionrpcRelative to #14288