From f3d04387815b2e5842a5a11d699cba1a52e2999f Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Mon, 26 Aug 2019 16:47:49 +0200 Subject: [PATCH] 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 --- src/core/ddsc/src/dds_reader.c | 8 ++++++-- src/core/ddsc/src/dds_writer.c | 9 +++++++-- src/core/ddsc/tests/reader.c | 11 +++++++++++ src/core/ddsc/tests/writer.c | 9 +++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/core/ddsc/src/dds_reader.c b/src/core/ddsc/src/dds_reader.c index ef58bfe..e746699 100644 --- a/src/core/ddsc/src/dds_reader.c +++ b/src/core/ddsc/src/dds_reader.c @@ -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); diff --git a/src/core/ddsc/src/dds_writer.c b/src/core/ddsc/src/dds_writer.c index 5908116..20fd418 100644 --- a/src/core/ddsc/src/dds_writer.c +++ b/src/core/ddsc/src/dds_writer.c @@ -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); diff --git a/src/core/ddsc/tests/reader.c b/src/core/ddsc/tests/reader.c index 2b53b99..c0d265c 100644 --- a/src/core/ddsc/tests/reader.c +++ b/src/core/ddsc/tests/reader.c @@ -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); +} +/*************************************************************************************************/ + diff --git a/src/core/ddsc/tests/writer.c b/src/core/ddsc/tests/writer.c index 4a9a8c2..9f3187e 100644 --- a/src/core/ddsc/tests/writer.c +++ b/src/core/ddsc/tests/writer.c @@ -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);