From d47cb3023828da211cd342f6d94d56c97d102227 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Mon, 25 Jul 2011 16:00:06 +0000 Subject: [PATCH] In rare circumstances, such as checksum errors, some network stacks can flag an fd for reading in select() and still block when the fd is read. Set all sockets non-blocking to prevent hangs when this occurs. (We don't actually handle the resulting EWOULDBLOCK or EAGAIN errors, so the rare cases will appear as communication failures and we will close the socket. This is already the case for TCP sockets and probably isn't a big deal.) ticket: 6933 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25048 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/sendto_kdc.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib/krb5/os/sendto_kdc.c b/src/lib/krb5/os/sendto_kdc.c index 371af9d23..541598787 100644 --- a/src/lib/krb5/os/sendto_kdc.c +++ b/src/lib/krb5/os/sendto_kdc.c @@ -758,6 +758,8 @@ start_connection(krb5_context context, struct conn_state *state, { int fd, e; unsigned int ssflags; + static const int one = 1; + static const struct linger lopt = { 0, 0 }; dprint("start_connection(@%p)\ngetting %s socket in family %d...", state, state->socktype == SOCK_STREAM ? "stream" : "dgram", state->family); @@ -769,12 +771,9 @@ start_connection(krb5_context context, struct conn_state *state, } set_cloexec_fd(fd); /* Make it non-blocking. */ + if (ioctlsocket(fd, FIONBIO, (const void *) &one)) + dperror("sendto_kdc: ioctl(FIONBIO)"); if (state->socktype == SOCK_STREAM) { - static const int one = 1; - static const struct linger lopt = { 0, 0 }; - - if (ioctlsocket(fd, FIONBIO, (const void *) &one)) - dperror("sendto_kdc: ioctl(FIONBIO)"); if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &lopt, sizeof(lopt))) dperror("sendto_kdc: setsockopt(SO_LINGER)"); TRACE_SENDTO_KDC_TCP_CONNECT(context, state); -- 2.26.2