From 5b7e4f49787da905b9ec7d01eaf76462ca3a6e28 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 6 Jan 2007 16:51:42 +0000 Subject: [PATCH] * handle NULL sdrefs gracefully. * fix mutex locking order in DNSProcessResult git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1374 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-compat-libdns_sd/compat.c | 35 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/avahi-compat-libdns_sd/compat.c b/avahi-compat-libdns_sd/compat.c index 9dc2281..9d8ff1c 100644 --- a/avahi-compat-libdns_sd/compat.c +++ b/avahi-compat-libdns_sd/compat.c @@ -469,25 +469,26 @@ static void sdref_unref(DNSServiceRef sdref) { } int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdref) { - if (!sdref || sdref->n_ref <= 0) - return -1; AVAHI_WARN_LINKAGE; + if (!sdref || sdref->n_ref <= 0) + return -1; + return sdref->main_fd; } DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdref) { DNSServiceErrorType ret = kDNSServiceErr_Unknown; - assert(sdref); - assert(sdref->n_ref >= 1); - AVAHI_WARN_LINKAGE; - ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex)); - + if (!sdref || sdref->n_ref <= 0) + return kDNSServiceErr_BadParam; + sdref_ref(sdref); + + ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex)); /* Cleanup notification socket */ if (read_command(sdref->main_fd) != COMMAND_POLL_DONE) @@ -512,10 +513,10 @@ DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdref) { finish: - sdref_unref(sdref); - ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex)); + sdref_unref(sdref); + return ret; } @@ -613,7 +614,6 @@ DNSServiceErrorType DNSSD_API DNSServiceBrowse( if (!ret_sdref) return kDNSServiceErr_BadParam; - *ret_sdref = NULL; assert(regtype); @@ -739,7 +739,10 @@ DNSServiceErrorType DNSSD_API DNSServiceResolve( AVAHI_WARN_LINKAGE; - assert(ret_sdref); + if (!ret_sdref) + return kDNSServiceErr_BadParam; + *ret_sdref = NULL; + assert(name); assert(regtype); assert(domain); @@ -853,7 +856,10 @@ DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains( AVAHI_WARN_LINKAGE; - assert(ret_sdref); + if (!ret_sdref) + return kDNSServiceErr_BadParam; + *ret_sdref = NULL; + assert(callback); if (interface == kDNSServiceInterfaceIndexLocalOnly || @@ -1096,7 +1102,6 @@ DNSServiceErrorType DNSSD_API DNSServiceRegister ( if (!ret_sdref) return kDNSServiceErr_BadParam; - *ret_sdref = NULL; if (!regtype) @@ -1210,10 +1215,12 @@ DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord( int ret = kDNSServiceErr_Unknown; AvahiStringList *txt = NULL; - assert(sdref); AVAHI_WARN_LINKAGE; + if (!sdref || sdref->n_ref <= 0) + return kDNSServiceErr_BadParam; + if (flags || rref) { AVAHI_WARN_UNSUPPORTED; return kDNSServiceErr_Unsupported; -- 2.39.5