-
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
Changes from 1 commit
95ca921
7ae906c
540713d
a926a2d
d5dd37b
546cd42
16835cf
0ff9758
b52276e
501f1f8
fb8b17e
85beb42
a173ecc
38344ba
1c9d1bb
045e50f
d51702d
0c867c9
828c444
46ecfe2
5508609
9a8cb65
24aad0a
2c00a3e
ef96f58
54dfbb3
4098f94
d83ad93
2c57792
e2b3b11
edc0670
590d616
9a528a6
203dbfa
2e925a8
d2134af
85cda1d
4e38577
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Fixed. |
||
env.test.fail(); | ||
else if (sle->isFieldPresent(sfFlags)) | ||
env.test.expect((sle->getFieldU32(sfFlags) & mask_) == 0); | ||
else | ||
env.test.pass(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ class AccountSet_test : public beast::unit_test::suite | |
env.fund(XRP(10000), noripple(alice)); | ||
// ask for the ledger entry - account root, to check its flags | ||
auto const jrr = env.le(alice); | ||
BEAST_EXPECT((*env.le(alice))[sfFlags] == 0u); | ||
BEAST_EXPECT(jrr && jrr->at(sfFlags) == 0u); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this file, there are 22 other dereferences of the But is it necessary to perform this type of null-pointer-check on all of them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wouldn't hurt to check. Even though it's been a while, I think it was the double call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize that I did note "Maybe there are more of these?" in the "Future Tasks" section of the description. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
} | ||
|
||
void | ||
|
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_
andnflags::account_
always hold a valid instance of theAccount
class. These data members are not pointers orstd::optional
values.Hence,
env.le(account_)
must always exist, isn't it? Are you envisioning a future modification to theseflags
andnflags
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 theAccount
is valid, a nullsle
could easily be returned. Consider this test: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.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.
okay, thanks for the clarification.