]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Properly handle EOF condition on libkrad sockets 547/head
authorNathaniel McCallum <npmccallum@redhat.com>
Fri, 30 Sep 2016 14:03:33 +0000 (10:03 -0400)
committerGreg Hudson <ghudson@mit.edu>
Fri, 30 Sep 2016 16:36:29 +0000 (12:36 -0400)
In the previous code, when the remote peer performed an orderly shutdown
on the socket, libkrad would enter a state in which all future requests
timed out.  Instead, if the peer shuts down its socket, we need to
attempt to reopen it.

ticket: 8504 (new)
target_version: 1.14-next
tags: pullup

src/lib/krad/remote.c

index f6abc43c269079af38ec7c4b4a98a0c4548795ac..437f7e91ac66dc224af188f5179c1e65cdae06d2 100644 (file)
@@ -329,16 +329,15 @@ on_io_read(krad_remote *rr)
     /* Read the packet. */
     i = recv(verto_get_fd(rr->io), rr->buffer.data + rr->buffer.length,
              pktlen, 0);
-    if (i < 0) {
-        /* Should we try again? */
-        if (errno == EWOULDBLOCK || errno == EAGAIN || errno == EINTR)
-            return;
 
-        /* The socket is unrecoverable. */
+    /* On these errors, try again. */
+    if (i < 0 && (errno == EWOULDBLOCK || errno == EAGAIN || errno == EINTR))
+        return;
+
+    /* On any other errors or on EOF, the socket is unrecoverable. */
+    if (i <= 0) {
         remote_shutdown(rr);
         return;
-    } else if (i == 0) {
-        remote_del_flags(rr, FLAGS_READ);
     }
 
     /* If we have a partial read or just the header, try again. */