]> git.meshlink.io Git - catta/commitdiff
add proper argument validity checking to address and hostname resolvers (closes #18)
authorLennart Poettering <lennart@poettering.net>
Thu, 2 Mar 2006 00:59:10 +0000 (00:59 +0000)
committerLennart Poettering <lennart@poettering.net>
Thu, 2 Mar 2006 00:59:10 +0000 (00:59 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1166 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-core/resolve-address.c
avahi-core/resolve-host-name.c

index a278beebbb6c99d7938d6f7dd38395c7db9173dc..25d21ace6e4f49be625c65cfae3c2f5eb5a2159a 100644 (file)
@@ -193,18 +193,11 @@ AvahiSAddressResolver *avahi_s_address_resolver_new(
     assert(address);
     assert(callback);
 
-    assert(address->proto == AVAHI_PROTO_INET || address->proto == AVAHI_PROTO_INET6);
-
-    if (!AVAHI_IF_VALID(interface)) {
-        avahi_server_set_errno(server, AVAHI_ERR_INVALID_INTERFACE);
-        return NULL;
-    }
-
-    if (!AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) {
-        avahi_server_set_errno(server, AVAHI_ERR_INVALID_FLAGS);
-        return NULL;
-    }
-
+    AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE);
+    AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_PROTO_VALID(protocol), AVAHI_ERR_INVALID_PROTOCOL);
+    AVAHI_CHECK_VALIDITY_RETURN_NULL(server, address->proto == AVAHI_PROTO_INET || address->proto == AVAHI_PROTO_INET6, AVAHI_ERR_INVALID_PROTOCOL);
+    AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
+    
     avahi_reverse_lookup_name(address, n, sizeof(n));
 
     if (!(k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR))) {
index a38c0014736657ab58eda8fd18b74245d4589e36..69a3adf4c273672163752e4b0c661939c942274f 100644 (file)
@@ -220,22 +220,11 @@ AvahiSHostNameResolver *avahi_s_host_name_resolver_new(
     assert(host_name);
     assert(callback);
 
-    assert(aprotocol == AVAHI_PROTO_UNSPEC || aprotocol == AVAHI_PROTO_INET || aprotocol == AVAHI_PROTO_INET6);
-
-    if (!AVAHI_IF_VALID(interface)) {
-        avahi_server_set_errno(server, AVAHI_ERR_INVALID_INTERFACE);
-        return NULL;
-    }
-
-    if (!avahi_is_valid_domain_name(host_name)) {
-        avahi_server_set_errno(server, AVAHI_ERR_INVALID_HOST_NAME);
-        return NULL;
-    }
-
-    if (!AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) {
-        avahi_server_set_errno(server, AVAHI_ERR_INVALID_FLAGS);
-        return NULL;
-    }
+    AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE);
+    AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_PROTO_VALID(protocol), AVAHI_ERR_INVALID_PROTOCOL);
+    AVAHI_CHECK_VALIDITY_RETURN_NULL(server, avahi_is_valid_domain_name(host_name), AVAHI_ERR_INVALID_DOMAIN_NAME);
+    AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_PROTO_VALID(aprotocol), AVAHI_ERR_INVALID_PROTOCOL);
+    AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
 
     if (!(r = avahi_new(AvahiSHostNameResolver, 1))) {
         avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
@@ -259,7 +248,6 @@ AvahiSHostNameResolver *avahi_s_host_name_resolver_new(
 
     r->record_browser_aaaa = r->record_browser_a = NULL;
 
-
     if (aprotocol == AVAHI_PROTO_INET || aprotocol == AVAHI_PROTO_UNSPEC) {
         k = avahi_key_new(host_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A);
         r->record_browser_a = avahi_s_record_browser_new(server, interface, protocol, k, flags, record_browser_callback, r);