Skip to content

Commit dae89c4

Browse files
committed
Handle errors from socket calls
Adds handling for socket() or read() returning a negative value (indicating an error has occurred). Upstream-Status: Submitted [dts@apple.com] Signed-off-by: Nate Karstens <nate.karstens@garmin.com> Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
1 parent 8ebfeaf commit dae89c4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mDNSPosix/mDNSPosix.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ mDNSlocal void ProcessRoutingNotification(int sd, GenLinkedList *change
16771677
// Read through the messages on sd and if any indicate that any interface records should
16781678
// be torn down and rebuilt, return affected indices as a bitmask. Otherwise return 0.
16791679
{
1680-
ssize_t readCount;
1680+
ssize_t readVal, readCount;
16811681
char buff[4096];
16821682
struct nlmsghdr *pNLMsg = (struct nlmsghdr*) buff;
16831683

@@ -1686,7 +1686,10 @@ mDNSlocal void ProcessRoutingNotification(int sd, GenLinkedList *change
16861686
// enough to hold all pending data and so avoid message fragmentation.
16871687
// (Note that FIONREAD is not supported on AF_NETLINK.)
16881688

1689-
readCount = read(sd, buff, sizeof buff);
1689+
readVal = read(sd, buff, sizeof buff);
1690+
if (readVal < 0) return;
1691+
readCount = readVal;
1692+
16901693
while (1)
16911694
{
16921695
// Make sure we've got an entire nlmsghdr in the buffer, and payload, too.
@@ -1702,7 +1705,9 @@ mDNSlocal void ProcessRoutingNotification(int sd, GenLinkedList *change
17021705
pNLMsg = (struct nlmsghdr*) buff;
17031706

17041707
// read more data
1705-
readCount += read(sd, buff + readCount, sizeof buff - readCount);
1708+
readVal = read(sd, buff + readCount, sizeof buff - readCount);
1709+
if (readVal < 0) return;
1710+
readCount += readVal;
17061711
continue; // spin around and revalidate with new readCount
17071712
}
17081713
else
@@ -2017,6 +2022,7 @@ mDNSlocal mDNSBool mDNSPlatformInit_CanReceiveUnicast(void)
20172022
int err;
20182023
int s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
20192024
struct sockaddr_in s5353;
2025+
if (s < 0) return mDNSfalse;
20202026
s5353.sin_family = AF_INET;
20212027
s5353.sin_port = MulticastDNSPort.NotAnInteger;
20222028
s5353.sin_addr.s_addr = 0;

0 commit comments

Comments
 (0)