-
Notifications
You must be signed in to change notification settings - Fork 36.7k
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
test, build: Enable -Werror=sign-compare #18216
Conversation
This is failing on the ARM64 Travis build: CXX util/libbitcoin_util_a-asmap.o
CXX util/libbitcoin_util_a-bip32.o
util/asmap.cpp: In function ‘uint32_t Interpret(const std::vector<bool>&, const std::vector<bool>&)’:
util/asmap.cpp:82:26: error: comparison of integer expressions of different signedness: ‘uint32_t’ {aka ‘unsigned int’} and ‘std::ptrdiff_t’ {aka ‘int’} [-Werror=sign-compare]
if (jump >= endpos - pos) break;
~~~~~^~~~~~~~~~~~~~~ |
7ab2e6c
to
416f3be
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
Thanks for doing this! I'm confident that adding I've reviewed the code and my only suggestion is to add Tested ACK 416f3be modulo above suggestion |
FWIW -- CVE-2017-18350 was signedness related: "CVE-2017-18350 is a buffer overflow vulnerability which allows a malicious |
416f3be
to
acee614
Compare
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.
ACK acee614
Concept ACK. |
src/util/asmap.cpp
Outdated
@@ -77,9 +77,10 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip) | |||
return DecodeASN(pos, endpos); | |||
} else if (opcode == 1) { | |||
jump = DecodeJump(pos, endpos); | |||
assert(pos + jump > pos); |
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.
Why this assert is needed here?
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 mean for that to protect against the unlikely case of overflow of pos + jump
overflowing - if an overflow occurs, pos + jump
will be less than pos
.
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.
Is the failure condition possible (pos + jump <= pos
)? If it is possible to reach I'm not certain aborting is the right thing to do :)
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 don't think this should be an assert. It can be caused by incorrect input (an corrupt asmap
file), not just developer errors. We shouldn't use assert for error handling. Don't we have other ways of reporting an error here?
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.
Updated to break
which results in returning 0
, which is not a valid ASN.
Tested on macOS 10.15.3:
|
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.
ACK acee614
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.
ACK acee614
Can remove some of the lines in |
Could also split up the test changes to merge them in the fast track? The Core changes seem controversial for now. |
acee614
to
b8a6a2d
Compare
ACK b8a6a2d -- patch looks correct |
ba1b64a
to
ab36ecf
Compare
Rebased for #18512 |
@Empact Looks good, but this one needs to be fixed for the ARM job to succeed :)
|
Also #18686. |
ab36ecf
to
054cc19
Compare
Explicitly add -Wsign-compare as well - not required for all compilers, as GCC activates it under -Wall, but may impact clang, etc.
054cc19
to
6853727
Compare
ACK 6853727 As noted in earlier comments: I'm confident this change will help us catch a non-zero amount of bugs hitting |
re-ACK 6853727 |
Removes the unused function warning when building on macOS. Now that bitcoin#18216 is in, with this change we'll be back to warningless builds on macOS. random.cpp:259:13: warning: unused function 'GetDevURandom' [-Wunused-function] static void GetDevURandom(unsigned char *ent32) ^ 1 warning generated.
Summary: test: Fix outstanding -Wsign-compare errors refactor: Rework asmap Interpret to avoid ptrdiff_t This is a backport of Core [[bitcoin/bitcoin#18216 | PR18216]] It also includes a change in asmap.cpp that was missed in D9055 ([[bitcoin/bitcoin#18512 | PR18512]]) Test Plan: ninja all check-all Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D9197
I went ahead and reverted the asmap changes, because they rely on UB: #21802 |
6853727 build: Enable -Werror=sign-compare (Ben Woosley) eac6a30 refactor: Rework asmap Interpret to avoid ptrdiff_t (Ben Woosley) df37377 test: Fix outstanding -Wsign-compare errors (Ben Woosley) Pull request description: Disallowing sign-comparison mismatches can help to prevent the introduction of overflow and interpretation bugs. In this case, ~all~ most existing violations are in the tests, and most simply required annotating the literal as unsigned for comparison. This was previously prevented by violations in leveldb which were fixed upstream and merged in bitcoin#17398. You can test that by building this branch against: 22d1118 vs 75fb37c ACKs for top commit: fjahr: re-ACK 6853727 practicalswift: ACK 6853727 Tree-SHA512: 14b5daa38c496fb51548feb30fb4dd179e6f76a8d355f52bc8e2a18f2f9340f0bc98dcf36d8b3d6521045d013891c3103749a4eda88ceef00202a6a0cf93f73c
6853727 build: Enable -Werror=sign-compare (Ben Woosley) eac6a30 refactor: Rework asmap Interpret to avoid ptrdiff_t (Ben Woosley) df37377 test: Fix outstanding -Wsign-compare errors (Ben Woosley) Pull request description: Disallowing sign-comparison mismatches can help to prevent the introduction of overflow and interpretation bugs. In this case, ~all~ most existing violations are in the tests, and most simply required annotating the literal as unsigned for comparison. This was previously prevented by violations in leveldb which were fixed upstream and merged in bitcoin#17398. You can test that by building this branch against: 22d1118 vs 75fb37c ACKs for top commit: fjahr: re-ACK 6853727 practicalswift: ACK 6853727 Tree-SHA512: 14b5daa38c496fb51548feb30fb4dd179e6f76a8d355f52bc8e2a18f2f9340f0bc98dcf36d8b3d6521045d013891c3103749a4eda88ceef00202a6a0cf93f73c
6853727 build: Enable -Werror=sign-compare (Ben Woosley) eac6a30 refactor: Rework asmap Interpret to avoid ptrdiff_t (Ben Woosley) df37377 test: Fix outstanding -Wsign-compare errors (Ben Woosley) Pull request description: Disallowing sign-comparison mismatches can help to prevent the introduction of overflow and interpretation bugs. In this case, ~all~ most existing violations are in the tests, and most simply required annotating the literal as unsigned for comparison. This was previously prevented by violations in leveldb which were fixed upstream and merged in bitcoin#17398. You can test that by building this branch against: 22d1118 vs 75fb37c ACKs for top commit: fjahr: re-ACK 6853727 practicalswift: ACK 6853727 Tree-SHA512: 14b5daa38c496fb51548feb30fb4dd179e6f76a8d355f52bc8e2a18f2f9340f0bc98dcf36d8b3d6521045d013891c3103749a4eda88ceef00202a6a0cf93f73c
6853727 build: Enable -Werror=sign-compare (Ben Woosley) eac6a30 refactor: Rework asmap Interpret to avoid ptrdiff_t (Ben Woosley) df37377 test: Fix outstanding -Wsign-compare errors (Ben Woosley) Pull request description: Disallowing sign-comparison mismatches can help to prevent the introduction of overflow and interpretation bugs. In this case, ~all~ most existing violations are in the tests, and most simply required annotating the literal as unsigned for comparison. This was previously prevented by violations in leveldb which were fixed upstream and merged in bitcoin#17398. You can test that by building this branch against: 22d1118 vs 75fb37c ACKs for top commit: fjahr: re-ACK 6853727 practicalswift: ACK 6853727 Tree-SHA512: 14b5daa38c496fb51548feb30fb4dd179e6f76a8d355f52bc8e2a18f2f9340f0bc98dcf36d8b3d6521045d013891c3103749a4eda88ceef00202a6a0cf93f73c
6853727 build: Enable -Werror=sign-compare (Ben Woosley) eac6a30 refactor: Rework asmap Interpret to avoid ptrdiff_t (Ben Woosley) df37377 test: Fix outstanding -Wsign-compare errors (Ben Woosley) Pull request description: Disallowing sign-comparison mismatches can help to prevent the introduction of overflow and interpretation bugs. In this case, ~all~ most existing violations are in the tests, and most simply required annotating the literal as unsigned for comparison. This was previously prevented by violations in leveldb which were fixed upstream and merged in bitcoin#17398. You can test that by building this branch against: 22d1118 vs 75fb37c ACKs for top commit: fjahr: re-ACK 6853727 practicalswift: ACK 6853727 Tree-SHA512: 14b5daa38c496fb51548feb30fb4dd179e6f76a8d355f52bc8e2a18f2f9340f0bc98dcf36d8b3d6521045d013891c3103749a4eda88ceef00202a6a0cf93f73c
6853727 build: Enable -Werror=sign-compare (Ben Woosley) eac6a30 refactor: Rework asmap Interpret to avoid ptrdiff_t (Ben Woosley) df37377 test: Fix outstanding -Wsign-compare errors (Ben Woosley) Pull request description: Disallowing sign-comparison mismatches can help to prevent the introduction of overflow and interpretation bugs. In this case, ~all~ most existing violations are in the tests, and most simply required annotating the literal as unsigned for comparison. This was previously prevented by violations in leveldb which were fixed upstream and merged in bitcoin#17398. You can test that by building this branch against: 22d1118 vs 75fb37c ACKs for top commit: fjahr: re-ACK 6853727 practicalswift: ACK 6853727 Tree-SHA512: 14b5daa38c496fb51548feb30fb4dd179e6f76a8d355f52bc8e2a18f2f9340f0bc98dcf36d8b3d6521045d013891c3103749a4eda88ceef00202a6a0cf93f73c
Disallowing sign-comparison mismatches can help to prevent the introduction of overflow and interpretation bugs.
In this case,
allmost existing violations are in the tests, and most simply required annotating the literal as unsigned for comparison.This was previously prevented by violations in leveldb which were fixed upstream and merged in #17398. You can test that by building this branch against: 22d1118 vs 75fb37c