Fix overwriting an agent counter with sender counter during updating keys #2064
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi. I'm a newbie here, so please forgive me, if I fail to follow some kind of "code of conduct".
In
send_msg()
,CreateSecMSG()
uses (for persisting sender counter)keys
structure, which can be modified by main thread callingOS_UpdateKeys()
. Thus main thread can interfere with manager thread callingCreateSecMSG()
.To fix this,
CreateSecMSG()
must be called after obtainingsendmsg_mutex
lock.Otherwise under certain circumstances, quite common when adding new agents, an existing agent's counter is overwritten by sender counter e.g. in the following scenario:
Main thread (
HandleSecure()
):check_keyupdate()
OS_UpdateKeys()
OS_FreeKeys()
keys.keysize = 0
sleep(1)
, thus transferring control to the main thread and increasing probability of the following.Manager thread:
CreateSecMSG()
(e.g. fromsend_msg()
called fromsend_file_toagent()
called fromread_controlmsg()
called fromwait_for_msgs()
)StoreSenderCounter()
, which stores sender counter tokeys->keyentries[keys->keysize]->fp
keys->keysize
is 0, instead of writing to "queue/rids/sender_counter" file, the counter is written to "queue/rids/NNN", where NNN is the lowest agent ID.