Snap for 7478067 from 367fbcafb56896f8da3bf09581becc6161ae2563 to mainline-extservices-release

Change-Id: I935da6768698d76d5c69222807a37425370a7204
diff --git a/Android.bp b/Android.bp
index bcc742a..30cba16 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,3 +1,36 @@
+package {
+    default_applicable_licenses: ["external_mdnsresponder_license"],
+}
+
+// Added automatically by a large-scale-change that took the approach of
+// 'apply every license found to every target'. While this makes sure we respect
+// every license restriction, it may not be entirely correct.
+//
+// e.g. GPL in an MIT project might only apply to the contrib/ directory.
+//
+// Please consider splitting the single license below into multiple licenses,
+// taking care not to lose any license_kind information, and overriding the
+// default license using the 'licenses: [...]' property on targets as needed.
+//
+// For unused files, consider creating a 'fileGroup' with "//visibility:private"
+// to attach the license to, and including a comment whether the files may be
+// used in the current project.
+// See: http://go/android-license-faq
+license {
+    name: "external_mdnsresponder_license",
+    visibility: [":__subpackages__"],
+    license_kinds: [
+        "SPDX-license-identifier-Apache-2.0",
+        "SPDX-license-identifier-BSD",
+        "SPDX-license-identifier-NCSA",
+        "SPDX-license-identifier-OpenSSL",
+        "legacy_notice",
+    ],
+    license_text: [
+        "LICENSE",
+    ],
+}
+
 cc_defaults {
     name: "mdnsresponder_default_cflags",
 
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..d97975c
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,3 @@
+third_party {
+  license_type: NOTICE
+}
diff --git a/NOTICE b/NOTICE
deleted file mode 100644
index f458904..0000000
--- a/NOTICE
+++ /dev/null
@@ -1,13 +0,0 @@
-The majority of the source code in the mDNSResponder project is licensed
-under the terms of the Apache License, Version 2.0, available from:
-   <http://www.apache.org/licenses/LICENSE-2.0>
-
-To accommodate license compatibility with the widest possible range
-of client code licenses, the shared library code, which is linked
-at runtime into the same address space as the client using it, is
-licensed under the terms of the "Three-Clause BSD License".
-
-The Linux Name Service Switch code, contributed by National ICT
-Australia Ltd (NICTA) is licensed under the terms of the NICTA Public
-Software Licence (which is substantially similar to the "Three-Clause
-BSD License", with some additional language pertaining to Australian law).
diff --git a/OWNERS b/OWNERS
index bdc2ff6..fe287c2 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,4 +1,5 @@
 # Default code reviewers picked from top 3 or more developers.
 # Please update this list if you find better candidates.
 sadmac@google.com
+include platform/packages/modules/adb:/OWNERS
 include platform/system/netd:/OWNERS
diff --git a/mDNSShared/dnssd_clientstub.c b/mDNSShared/dnssd_clientstub.c
index 88f20eb..637c83c 100644
--- a/mDNSShared/dnssd_clientstub.c
+++ b/mDNSShared/dnssd_clientstub.c
@@ -260,16 +260,23 @@
 		}
 	else 
 		{
-		// Compute the number of integers needed for storing "sd". Internally fd_set is stored
-		// as an array of ints with one bit for each fd and hence we need to compute
-		// the number of ints needed rather than the number of bytes. If "sd" is 32, we need
-		// two ints and not just one.
-		int nfdbits = sizeof (int) * 8;
-		int nints = (sd/nfdbits) + 1;
-		fs = (fd_set *)calloc(nints, sizeof(int));
+		// Compute the number of longs needed for storing "sd". Internally fd_set is stored
+		// as an array of longs with one bit for each fd and hence we need to compute
+		// the number of longs needed rather than the number of bytes. If "sd" is 64, we need
+		// two longs and not just one.
+		int nfdbits = sizeof (unsigned long) * 8;
+		int nlongs = (sd/nfdbits) + 1;
+		fs = (fd_set *)calloc(nlongs, sizeof(unsigned long));
 		if (fs == NULL) { syslog(LOG_WARNING, "dnssd_clientstub more_bytes: malloc failed"); return 0; }
 		}
-	FD_SET(sd, fs);
+
+	#ifdef __BIONIC__
+		// The regular FD_SET() macro in Bionic is unaware of the above workaround,
+		// and would abort on sd >= 1024. Use the unchecked __FD_SET() instead.
+		__FD_SET(sd, fs);
+	#else
+		FD_SET(sd, fs);
+	#endif
 	ret = select((int)sd+1, fs, (fd_set*)NULL, (fd_set*)NULL, &tv);
 	if (fs != &readfds) free(fs);
 	return (ret > 0);