1*4a64e381SAndroid Build Coastguard WorkerFrom dae89c4e97faf408394961c0f4b1577a7d5976cc Mon Sep 17 00:00:00 2001
2*4a64e381SAndroid Build Coastguard WorkerMessage-ID: <dae89c4e97faf408394961c0f4b1577a7d5976cc.1687508149.git.stefan@agner.ch>
3*4a64e381SAndroid Build Coastguard WorkerIn-Reply-To: <e136dcdcdd93ef32ada981e89c195905eb809eea.1687508149.git.stefan@agner.ch>
4*4a64e381SAndroid Build Coastguard WorkerReferences: <e136dcdcdd93ef32ada981e89c195905eb809eea.1687508149.git.stefan@agner.ch>
5*4a64e381SAndroid Build Coastguard WorkerFrom: Nate Karstens <[email protected]>
6*4a64e381SAndroid Build Coastguard WorkerDate: Thu, 10 Aug 2017 08:27:32 -0500
7*4a64e381SAndroid Build Coastguard WorkerSubject: [PATCH] Handle errors from socket calls
8*4a64e381SAndroid Build Coastguard Worker
9*4a64e381SAndroid Build Coastguard WorkerAdds handling for socket() or read() returning a
10*4a64e381SAndroid Build Coastguard Workernegative value (indicating an error has occurred).
11*4a64e381SAndroid Build Coastguard Worker
12*4a64e381SAndroid Build Coastguard WorkerUpstream-Status: Submitted [[email protected]]
13*4a64e381SAndroid Build Coastguard Worker
14*4a64e381SAndroid Build Coastguard WorkerSigned-off-by: Nate Karstens <[email protected]>
15*4a64e381SAndroid Build Coastguard WorkerSigned-off-by: Alex Kiernan <[email protected]>
16*4a64e381SAndroid Build Coastguard Worker---
17*4a64e381SAndroid Build Coastguard Worker mDNSPosix/mDNSPosix.c | 12 +++++++++---
18*4a64e381SAndroid Build Coastguard Worker 1 file changed, 9 insertions(+), 3 deletions(-)
19*4a64e381SAndroid Build Coastguard Worker
20*4a64e381SAndroid Build Coastguard Workerdiff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c
21*4a64e381SAndroid Build Coastguard Workerindex 010f266..89e108f 100644
22*4a64e381SAndroid Build Coastguard Worker--- a/mDNSPosix/mDNSPosix.c
23*4a64e381SAndroid Build Coastguard Worker+++ b/mDNSPosix/mDNSPosix.c
24*4a64e381SAndroid Build Coastguard Worker@@ -1677,7 +1677,7 @@ mDNSlocal void          ProcessRoutingNotification(int sd, GenLinkedList *change
25*4a64e381SAndroid Build Coastguard Worker // Read through the messages on sd and if any indicate that any interface records should
26*4a64e381SAndroid Build Coastguard Worker // be torn down and rebuilt, return affected indices as a bitmask. Otherwise return 0.
27*4a64e381SAndroid Build Coastguard Worker {
28*4a64e381SAndroid Build Coastguard Worker-    ssize_t readCount;
29*4a64e381SAndroid Build Coastguard Worker+    ssize_t readVal, readCount;
30*4a64e381SAndroid Build Coastguard Worker     char buff[4096];
31*4a64e381SAndroid Build Coastguard Worker     struct nlmsghdr         *pNLMsg = (struct nlmsghdr*) buff;
32*4a64e381SAndroid Build Coastguard Worker
33*4a64e381SAndroid Build Coastguard Worker@@ -1686,7 +1686,10 @@ mDNSlocal void          ProcessRoutingNotification(int sd, GenLinkedList *change
34*4a64e381SAndroid Build Coastguard Worker     // enough to hold all pending data and so avoid message fragmentation.
35*4a64e381SAndroid Build Coastguard Worker     // (Note that FIONREAD is not supported on AF_NETLINK.)
36*4a64e381SAndroid Build Coastguard Worker
37*4a64e381SAndroid Build Coastguard Worker-    readCount = read(sd, buff, sizeof buff);
38*4a64e381SAndroid Build Coastguard Worker+    readVal = read(sd, buff, sizeof buff);
39*4a64e381SAndroid Build Coastguard Worker+    if (readVal < 0) return;
40*4a64e381SAndroid Build Coastguard Worker+    readCount = readVal;
41*4a64e381SAndroid Build Coastguard Worker+
42*4a64e381SAndroid Build Coastguard Worker     while (1)
43*4a64e381SAndroid Build Coastguard Worker     {
44*4a64e381SAndroid Build Coastguard Worker         // Make sure we've got an entire nlmsghdr in the buffer, and payload, too.
45*4a64e381SAndroid Build Coastguard Worker@@ -1702,7 +1705,9 @@ mDNSlocal void          ProcessRoutingNotification(int sd, GenLinkedList *change
46*4a64e381SAndroid Build Coastguard Worker                 pNLMsg = (struct nlmsghdr*) buff;
47*4a64e381SAndroid Build Coastguard Worker
48*4a64e381SAndroid Build Coastguard Worker                 // read more data
49*4a64e381SAndroid Build Coastguard Worker-                readCount += read(sd, buff + readCount, sizeof buff - readCount);
50*4a64e381SAndroid Build Coastguard Worker+                readVal = read(sd, buff + readCount, sizeof buff - readCount);
51*4a64e381SAndroid Build Coastguard Worker+                if (readVal < 0) return;
52*4a64e381SAndroid Build Coastguard Worker+                readCount += readVal;
53*4a64e381SAndroid Build Coastguard Worker                 continue;                   // spin around and revalidate with new readCount
54*4a64e381SAndroid Build Coastguard Worker             }
55*4a64e381SAndroid Build Coastguard Worker             else
56*4a64e381SAndroid Build Coastguard Worker@@ -2017,6 +2022,7 @@ mDNSlocal mDNSBool mDNSPlatformInit_CanReceiveUnicast(void)
57*4a64e381SAndroid Build Coastguard Worker     int err;
58*4a64e381SAndroid Build Coastguard Worker     int s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
59*4a64e381SAndroid Build Coastguard Worker     struct sockaddr_in s5353;
60*4a64e381SAndroid Build Coastguard Worker+    if (s < 0) return mDNSfalse;
61*4a64e381SAndroid Build Coastguard Worker     s5353.sin_family      = AF_INET;
62*4a64e381SAndroid Build Coastguard Worker     s5353.sin_port        = MulticastDNSPort.NotAnInteger;
63*4a64e381SAndroid Build Coastguard Worker     s5353.sin_addr.s_addr = 0;
64*4a64e381SAndroid Build Coastguard Worker--
65*4a64e381SAndroid Build Coastguard Worker2.41.0
66*4a64e381SAndroid Build Coastguard Worker
67