summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2011-07-25 16:00:06 +0000
committerGreg Hudson <ghudson@mit.edu>2011-07-25 16:00:06 +0000
commitd47cb3023828da211cd342f6d94d56c97d102227 (patch)
tree5c972c560a019e96a233b879bfe10a4aef266ccc /src
parente0273bc4d14db73824b0f1fcfcba5c26c2ae2e21 (diff)
downloadkrb5-d47cb3023828da211cd342f6d94d56c97d102227.tar.gz
krb5-d47cb3023828da211cd342f6d94d56c97d102227.tar.xz
krb5-d47cb3023828da211cd342f6d94d56c97d102227.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/lib/krb5/os/sendto_kdc.c9
1 files 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);