libmsdnssd: Restore support for more than 1024 open file descriptors

The shared code in mDNSShared/dnssd_clientstub.c is still based on the
deprecated select(), which uses the fixed-size fd_set bitfield, normally
limited to FD_SETSIZE (1024).

The DNSServiceProcessResult() API already included a workaround to
overcome this limit which consisted in allocating a dynamic fd_set on
the heap.

Unfortunately, the FD_SET() macro in Android is unaware of this and
helpfully invokes abort() anyway!  The fix consists in using the
unchecked __FD_SET() macro so that the original workaround continues
to work.

And actually, the original workaround had another issue: on 64bit
systems, it allocated buffers which are too short for the 64bit writes
done by Bionic's FD_SET(). This bug is harmless in production code
because calloc() will round up blocks to 8-bytes, but it would result
in ASAN hits.

Note that there are several other places in this codebase where FD_SET()
is used without a workaround, but it seems that none of them are
currently being called by netd, so we can leave them alone for now.

The better fix would be porting everything to poll(), but since this
codebase is ancient and comes with no tests, I would advise against it.

Bug: 171680117
Test: haha, this codebase has no tests
Test: atest system/netd
Change-Id: I8970429ef4e0135453e01f6855b1b89e22b937e5
1 file changed