From 2e6ea36fda40e62e02444c8dc53d5e222b49e66e Mon Sep 17 00:00:00 2001 From: Dennis Potman Date: Fri, 15 May 2020 14:10:11 +0200 Subject: [PATCH] Fix a race condition in delete_participant, that could occur on security permissions or identity expiry, which triggers a delete of the local participant Signed-off-by: Dennis Potman --- src/core/ddsi/src/ddsi_security_omg.c | 2 +- src/core/ddsi/src/q_entity.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/ddsi/src/ddsi_security_omg.c b/src/core/ddsi/src/ddsi_security_omg.c index 79052b2..9ef815a 100644 --- a/src/core/ddsi/src/ddsi_security_omg.c +++ b/src/core/ddsi/src/ddsi_security_omg.c @@ -842,7 +842,7 @@ static bool delete_pp_by_handle (DDS_Security_Handle handle, expired_pp_check_fn { if (q_omg_participant_is_secure (pp) && expired_pp_check_fn (pp, handle)) { - delete_participant (gv, &pp->e.guid); + (void) delete_participant (gv, &pp->e.guid); result = true; } } diff --git a/src/core/ddsi/src/q_entity.c b/src/core/ddsi/src/q_entity.c index b8858ca..4fb30cd 100644 --- a/src/core/ddsi/src/q_entity.c +++ b/src/core/ddsi/src/q_entity.c @@ -1308,14 +1308,19 @@ dds_return_t delete_participant (struct ddsi_domaingv *gv, const struct ddsi_gui { struct participant *pp; GVLOGDISC ("delete_participant("PGUIDFMT")\n", PGUID (*ppguid)); + ddsrt_mutex_lock (&gv->lock); if ((pp = entidx_lookup_participant_guid (gv->entity_index, ppguid)) == NULL) + { + ddsrt_mutex_unlock (&gv->lock); return DDS_RETCODE_BAD_PARAMETER; + } builtintopic_write (gv->builtin_topic_interface, &pp->e, ddsrt_time_wallclock(), false); remember_deleted_participant_guid (gv->deleted_participants, &pp->e.guid); #ifdef DDSI_INCLUDE_SECURITY disconnect_participant_secure (pp); #endif entidx_remove_participant_guid (gv->entity_index, pp); + ddsrt_mutex_unlock (&gv->lock); gcreq_participant (pp); return 0; }