Browse Source

Stack: Correctly check if mDNS is self-announce if discovery url ends with slash

Stefan Profanter 5 years ago
parent
commit
f719f8e970
1 changed files with 22 additions and 2 deletions
  1. 22 2
      src/server/ua_server_discovery_mdns.c

+ 22 - 2
src/server/ua_server_discovery_mdns.c

@@ -106,7 +106,7 @@ mdns_record_add_or_get(UA_DiscoveryManager *dm, const char *record, const char *
 
 /* see http://stackoverflow.com/a/10838854/869402 */
 static IP_ADAPTER_ADDRESSES *
-getInterfaces(UA_Server *server) {
+getInterfaces(const UA_Server *server) {
     IP_ADAPTER_ADDRESSES* adapter_addresses = NULL;
 
     /* Start with a 16 KB buffer and resize if needed - multiple attempts in
@@ -151,12 +151,32 @@ getInterfaces(UA_Server *server) {
 #endif /* _WIN32 */
 
 static UA_Boolean
-mdns_is_self_announce(UA_Server *server, struct serverOnNetwork_list_entry *entry) {
+mdns_is_self_announce(const UA_Server *server, const struct serverOnNetwork_list_entry *entry) {
     for (size_t i=0; i<server->config.networkLayersSize; i++) {
         UA_ServerNetworkLayer *nl = &server->config.networkLayers[i];
         if(UA_String_equal(&entry->serverOnNetwork.discoveryUrl,
                            &nl->discoveryUrl))
             return true;
+		// check discoveryUrl ignoring tailing slash
+        if (((
+        		nl->discoveryUrl.length == entry->serverOnNetwork.discoveryUrl.length +1 &&
+        		nl->discoveryUrl.data[nl->discoveryUrl.length-1] == '/'
+			  ) || (
+				entry->serverOnNetwork.discoveryUrl.length == nl->discoveryUrl.length +1 &&
+				entry->serverOnNetwork.discoveryUrl.data[entry->serverOnNetwork.discoveryUrl.length-1] == '/'
+			  )
+			) &&
+        	memcmp(nl->discoveryUrl.data, entry->serverOnNetwork.discoveryUrl.data,
+        			UA_MIN(nl->discoveryUrl.length, entry->serverOnNetwork.discoveryUrl.length)) == 0
+        ) {
+        	return true;
+        }
+		if (nl->discoveryUrl.length == entry->serverOnNetwork.discoveryUrl.length +1 &&
+			nl->discoveryUrl.data[nl->discoveryUrl.length-1] == '/' &&
+			memcmp(nl->discoveryUrl.data, entry->serverOnNetwork.discoveryUrl.data, nl->discoveryUrl.length-1) == 0
+				) {
+			return true;
+		}
     }
 
     /* The discovery URL may also just contain the IP address, but in our