diff --git a/src/mdns/mdns_avahi.cpp b/src/mdns/mdns_avahi.cpp index 735a2c3a1ef..aaabe87d400 100644 --- a/src/mdns/mdns_avahi.cpp +++ b/src/mdns/mdns_avahi.cpp @@ -690,8 +690,13 @@ otbrError PublisherAvahi::PublishServiceImpl(const std::string &aHostName, otbrLogInfo("Commit avahi service %s.%s", serviceName.c_str(), aType.c_str()); avahiError = avahi_entry_group_commit(group); + + // Cauae a failure... + avahiError = AVAHI_ERR_INVALID_HOST_NAME; + VerifyOrExit(avahiError == AVAHI_OK); + AddServiceRegistration(std::unique_ptr(new AvahiServiceRegistration( aHostName, serviceName, aType, sortedSubTypeList, aPort, sortedTxtList, std::move(aCallback), group, this))); diff --git a/src/sdp_proxy/advertising_proxy.cpp b/src/sdp_proxy/advertising_proxy.cpp index 9f6ce494ad5..16b0579aa12 100644 --- a/src/sdp_proxy/advertising_proxy.cpp +++ b/src/sdp_proxy/advertising_proxy.cpp @@ -221,6 +221,16 @@ void AdvertisingProxy::PublishAllHostsAndServices(void) return; } +static void UpdateStuff(std::string &fullHostName, const otSrpServerHost *aHost) +{ + fullHostName = otSrpServerHostGetFullName(aHost); +} + +static void UpdateService(std::string &fullServiceName, const otSrpServerService *service) +{ + fullServiceName = otSrpServerServiceGetInstanceName(service); +} + otbrError AdvertisingProxy::PublishHostAndItsServices(const otSrpServerHost *aHost, OutstandingUpdate *aUpdate) { otbrError error = OTBR_ERROR_NONE; @@ -232,7 +242,16 @@ otbrError AdvertisingProxy::PublishHostAndItsServices(const otSrpServerHost *aHo const otSrpServerService *service; otSrpServerServiceUpdateId updateId = 0; bool hasUpdate = false; - std::string fullHostName = otSrpServerHostGetFullName(aHost); + std::string fullHostName; + + if (otSrpServerHostGetFullName(aHost) == nullptr) + { + otbrLogWarning("ABTIN ~~~ otSrpServerHostGetFullName() is null WHY?"); + error = OTBR_ERROR_INVALID_ARGS; + ExitNow(); + } + + UpdateStuff(fullHostName, aHost); otbrLogInfo("Advertise SRP service updates: host=%s", fullHostName.c_str()); @@ -256,11 +275,21 @@ otbrError AdvertisingProxy::PublishHostAndItsServices(const otSrpServerHost *aHo service = nullptr; while ((service = otSrpServerHostGetNextService(aHost, service)) != nullptr) { - std::string fullServiceName = otSrpServerServiceGetInstanceName(service); + std::string fullServiceName; std::string serviceName; std::string serviceType; std::string serviceDomain; + if (otSrpServerServiceGetInstanceName(service) == nullptr) + { + otbrLogWarning("ABTIN ~~~ otSrpServerServiceGetInstanceName() is null WHY?"); + error = OTBR_ERROR_INVALID_ARGS; + ExitNow(); + } + + UpdateService(fullServiceName, service); + // fullServiceName = otSrpServerServiceGetInstanceName(service); + SuccessOrExit(error = SplitFullServiceInstanceName(fullServiceName, serviceName, serviceType, serviceDomain)); if (!hostDeleted && !otSrpServerServiceIsDeleted(service))