cowsql / raft

Asynchronous C implementation of the Raft consensus protocol
https://raft.readthedocs.io
Other
45 stars 6 forks source link

Use of uninitialized memory in outgoing append entries result frames #183

Closed atlesn closed 5 months ago

atlesn commented 5 months ago

In rejection pathways when receiving append entries or install snapshot frames, the last_log_index field of the internal representation of the append entries result frame was not set. This uninitialized value was then written to the encoding buffer for outgoing append entries result frame and sent out.

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 74.09%. Comparing base (dd383c5) to head (9d911c1). Report is 2 commits behind head on main.

:exclamation: Current head 9d911c1 differs from pull request most recent head 09448e2. Consider uploading reports for the commit 09448e2 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #183 +/- ## ========================================== - Coverage 74.18% 74.09% -0.10% ========================================== Files 52 52 Lines 10367 10369 +2 Branches 2465 2465 ========================================== - Hits 7691 7683 -8 - Misses 1321 1330 +9 - Partials 1355 1356 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

freeekanayaka commented 5 months ago

There are a few rejection paths, do you know exactly which path we're talking about?

It seems that https://github.com/cowsql/raft/blob/9edb176a7924ce2b943cb56552366dc4b5a1a6b7/src/recv_append_entries.c#L44 indeed jumps to the reply label without setting last_log_index, but I'm not sure if there are other paths. If that's the only path, I'd probably suggest to set it there only. That would have the benefit that we don't accidentally mask other cases where we expect that value to be set, but in fact is not.

atlesn commented 5 months ago

I think it's only in the goto reply-case. I moved the initialization to inside the if-statement.

freeekanayaka commented 5 months ago

I think it's only in the goto reply-case. I moved the initialization to inside the if-statement.

Thanks.