Closed mszulcz-mitre closed 1 year ago
@HalosGhost As I was replying to your recent comment on Issue #141, I remembered this issue and thought I'd mention that it's similar. As with the bugs in #141, this bug allows an impossible state to be requested for sentinel_2pc::controller
. To avoid it, it seems reasonable to do a check in ::init()
.
It's funny, I had misread them and actually thought they were the same. Thank you for specifically calling my attention to it. And I agree that it's also quite reasonable to fix such things as a check (and subsequent failure) in ::init()
.
Affected Branch
trunk
Basic Diagnostics
[X] I've pulled the latest changes on the affected branch and the issue is still present.
[X] The issue is reproducible in docker
Description
In sentinel_2pc::controller, a nonexistent element in the vector
m_opts.m_sentinel_endpoints
can be accessed ifm_sentinel_id > m_opts.m_sentinel_endpoints.size() - 1
. The access occurs in Line 51 of src/ush/twophase/sentinel_2pc/controller.cpp:and in Line 70:
Accessing a nonexistent element via the [] operator results in undefined behavior. In my tests, the 1st access (Line 51) doesn't throw an error, but the 2nd access sometimes throws an error. To trigger the nonexistent-element access, you can add this unit test to controller_test.cpp:
Solution
A solution is to check whether
sentinel_id
is out of range ofm_opts.m_sentinel_endpoints
in sentinel_2pc::controller::init, and if it is, indicate that initialization failed by returning false. Something like this should work:Code of Conduct