Check that topic is from the same participant

Things go really badly wrong when topics from one participant are used
to create a reader/writer in another participant.  This returns an error
if they are not.

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2019-08-26 16:47:49 +02:00 committed by eboasson
parent 7feab2e982
commit f3d0438781
4 changed files with 33 additions and 4 deletions

View file

@ -347,8 +347,11 @@ dds_entity_t dds_create_reader (dds_entity_t participant_or_subscriber, dds_enti
goto err_tp_lock;
}
assert (tp->m_stopic);
/* FIXME: domain check */
assert (sub->m_entity.m_domain == tp->m_entity.m_domain);
if (sub->m_entity.m_participant != tp->m_entity.m_participant)
{
reader = DDS_RETCODE_BAD_PARAMETER;
goto err_pp_mismatch;
}
/* Merge qos from topic and subscriber, dds_copy_qos only fails when it is passed a null
argument, but that isn't the case here */
@ -414,6 +417,7 @@ dds_entity_t dds_create_reader (dds_entity_t participant_or_subscriber, dds_enti
return reader;
err_bad_qos:
err_pp_mismatch:
dds_topic_unlock (tp);
err_tp_lock:
dds_subscriber_unlock (sub);

View file

@ -274,9 +274,13 @@ dds_entity_t dds_create_writer (dds_entity_t participant_or_publisher, dds_entit
if ((rc = dds_topic_lock (topic, &tp)) != DDS_RETCODE_OK)
goto err_tp_lock;
assert (tp->m_stopic);
assert (pub->m_entity.m_domain == tp->m_entity.m_domain);
if (pub->m_entity.m_participant != tp->m_entity.m_participant)
{
rc = DDS_RETCODE_BAD_PARAMETER;
goto err_pp_mismatch;
}
/* Merge Topic & Publisher qos */
wqos = dds_create_qos ();
@ -326,6 +330,7 @@ dds_entity_t dds_create_writer (dds_entity_t participant_or_publisher, dds_entit
return writer;
err_bad_qos:
err_pp_mismatch:
dds_topic_unlock (tp);
err_tp_lock:
dds_publisher_unlock (pub);

View file

@ -277,6 +277,17 @@ CU_Theory((dds_entity_t *par, dds_entity_t *top), ddsc_reader_create, non_partic
}
/*************************************************************************************************/
/*************************************************************************************************/
CU_Test(ddsc_reader_create, wrong_participant, .init=reader_init, .fini=reader_fini)
{
dds_entity_t participant2 = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
CU_ASSERT_FATAL(participant2 > 0);
dds_entity_t reader = dds_create_reader(participant2, g_topic, NULL, NULL);
CU_ASSERT_EQUAL_FATAL(reader, DDS_RETCODE_BAD_PARAMETER);
dds_delete(participant2);
}
/*************************************************************************************************/

View file

@ -72,6 +72,15 @@ CU_Test(ddsc_create_writer, participant, .init = setup, .fini = teardown)
CU_ASSERT_FATAL(writer > 0);
}
CU_Test(ddsc_create_writer, wrong_participant, .init = setup, .fini = teardown)
{
dds_entity_t participant2 = dds_create_participant(DDS_DOMAIN_DEFAULT, NULL, NULL);
CU_ASSERT_FATAL(participant2 > 0);
writer = dds_create_writer(participant2, topic, NULL, NULL);
CU_ASSERT_EQUAL_FATAL(writer, DDS_RETCODE_BAD_PARAMETER);
dds_delete(participant2);
}
CU_Test(ddsc_create_writer, publisher, .init = setup, .fini = teardown)
{
writer = dds_create_writer(publisher, topic, NULL, NULL);