-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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: Check for some unlikely null dereferences in tests #5004
base: develop
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #5004 +/- ##
=========================================
+ Coverage 76.1% 77.4% +1.3%
=========================================
Files 762 762
Lines 61469 64936 +3467
Branches 8121 8121
=========================================
+ Hits 46807 50280 +3473
+ Misses 14662 14656 -6 |
@@ -51,7 +51,9 @@ void | |||
nflags::operator()(Env& env) const | |||
{ | |||
auto const sle = env.le(account_); | |||
if (sle->isFieldPresent(sfFlags)) | |||
if (!sle) |
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.
Before line 44 (above), for the sake of consistency, we need to introduce a similar check
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.
Good catch. Fixed.
@@ -51,7 +51,9 @@ void | |||
nflags::operator()(Env& env) const | |||
{ | |||
auto const sle = env.le(account_); |
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.
The data members flags::account_
and nflags::account_
always hold a valid instance of the Account
class. These data members are not pointers or std::optional
values.
Hence, env.le(account_)
must always exist, isn't it? Are you envisioning a future modification to these flags
and nflags
classes, due to which a null pointer might be returned 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.
A valid instance of an Account
does not guarantee that that account has been created / funded on the ledger. So even though the Account
is valid, a null sle
could easily be returned. Consider this test:
Env env{*this};
Account alice("alice");
env.require(flags(alice, asfRequireDest));
env.require(nflags(alice, asfRequireAuth));
That's a perfectly validly written test, but without this change, it'll dereference a null SLE
and crash. With this change, the test will fail in the changed functions, but it won't crash.
* upstream/develop: Set version to 2.2.0-rc1
* upstream/develop: Remove flow assert: (5009) Update list of maintainers: (4984)
* upstream/develop: Add external directory to Conan recipe's exports (5006) Add missing includes (5011)
* commit 'c706926': (23 commits) Change order of checks in amm_info: (4924) Add the fixEnforceNFTokenTrustline amendment: (4946) Replaces the usage of boost::string_view with std::string_view (4509) docs: explain how to find a clang-format patch generated by CI (4521) XLS-52d: NFTokenMintOffer (4845) chore: remove repeat words (5041) Expose all amendments known by libxrpl (5026) fixReducedOffersV2: prevent offers from blocking order books: (5032) Additional unit tests for testing deletion of trust lines (4886) Fix conan typo: (5044) Add new command line option to make replaying transactions easier: (5027) Fix compatibility with Conan 2.x: (5001) Set version to 2.2.0 Set version to 2.2.0-rc3 Add xrpl.libpp as an exported lib in conan (5022) Fix Oracle's token pair deterministic order: (5021) Set version to 2.2.0-rc2 Fix last Liquidity Provider withdrawal: Fix offer crossing via single path AMM with transfer fee: Fix adjustAmountsByLPTokens(): ...
* commit 'f6879da': Add bin/physical.sh (4997) Prepare to rearrange sources: (4997)
* upstream/develop: fixInnerObjTemplate2 amendment (5047) Set version to 2.3.0-b1 Ignore restructuring commits (4997) Recompute loops (4997) Rewrite includes (4997) Rearrange sources (4997) Move CMake directory (4997)
* upstream/develop: fix CTID in tx command returns invalidParams on lowercase hex (5049) Invariant: prevent a deleted account from leaving (most) artifacts on the ledger. (4663) Bump codecov plugin version to version 4.5.0 (5055) fix "account_nfts" with unassociated marker returning issue (5045)
* upstream/develop: chore: remove repeat words (5053)
* upstream/develop: Add xrpld build option and Conan package test (5052)
* upstream/develop: Update BUILD.md after PR 5052 (5067)
* Add the same null check in the `flags` class as `nflags`.
* upstream/develop: chore: Add comments to SignerEntries.h (5059) chore: Rename two files from Directory* to Dir*: (5058)
* upstream/develop: Ensure levelization sorting is ASCII-order across platforms (5072) fix: Fix NuDB build error via Conan patch (5061) Disallow filtering account_objects by unsupported types (5056)
* upstream/develop: Update gcovr EXCLUDE (5084) Fix crash inside `OverlayImpl` loops over `ids_` (5071) Set version to 2.3.0-b2 docs: Document the process for merging pull requests (5010) Remove unused constants from resource/Fees.h (4856) fix: change error for invalid `feature` param in `feature` RPC (5063) Set version to 2.2.1 Use error codes throughout fast Base58 implementation Improve error handling in some RPC commands
* upstream/develop: Factor out Transactor::trapTransaction (5087) Remove shards (5066)
* upstream/develop: Address rare corruption of NFTokenPage linked list (4945)
* upstream/develop: chore: Fix documentation generation job: (5091) chore: libxrpl verification on CI (5028)
* upstream/develop: docs: Update options documentation (5083) refactor: Remove dead headers (5081) refactor: Remove reporting mode (5092)
* upstream/develop: Update Release Notes for 2.2.1 and 2.2.2 Set version to 2.2.2 Allow only 1 job queue slot for each validation ledger check Allow only 1 job queue slot for acquiring inbound ledger. Track latencies of certain code blocks, and log if they take too long
* upstream/develop: test: Retry RPC commands to try to fix MacOS CI jobs (5120)
* upstream/develop: Set version to 2.3.0-b4 feat(SQLite): allow configurable database pragma values (5135) refactor: re-order PRAGMA statements (5140) fix(book_changes): add "validated" field and reduce RPC latency (5096) chore: fix typos in comments (5094) Set version to 2.2.3 Update SQLite3 max_page_count to match current defaults (5114)
* upstream/develop: Expand Error Message for rpcInternal (4959) docs: clean up API-CHANGELOG.md (5064)
* upstream/develop: Consolidate definitions of fields, objects, transactions, and features (5122) Ignore reformat when blaming Reformat code with clang-format-18 Update pre-commit hook Update clang-format settings Update clang-format workflow
High Level Overview of Change
I stumbled upon these couple of places where test code could, but is very unlikely to, dereference a null pointer. I added a simple check to each of them.
Context of Change
This was a random find.
Even though these changes are tiny, I don't think they are insignificant enough to be considered "trivial", so I'm requesting two reviews.
Type of Change
Before / After
There should be no observable change, as tests aren't currently likely / able to get a null value.
Future Tasks
Maybe there are more of these?