7010989: Duplicate closure of file descriptors leads to unexpected and incorrect closure of sockets

Reviewed-by: chegar
This commit is contained in:
Ivan Gerasimov 2014-09-09 19:02:36 +04:00
parent 4ee0119566
commit 63af0e6c0d
3 changed files with 9 additions and 2 deletions

View File

@ -493,6 +493,9 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_bind0(JNIEnv *env, jobject this,
}
}
} else {
/* NET_BindV6() closes both sockets upon a failure */
(*env)->SetObjectField(env, this, pdsi_fdID, NULL);
(*env)->SetObjectField(env, this, pdsi_fd1ID, NULL);
NET_ThrowCurrent (env, "Cannot bind");
return;
}

View File

@ -467,6 +467,10 @@ Java_java_net_TwoStacksPlainSocketImpl_socketBind(JNIEnv *env, jobject this,
(*env)->SetIntField(env, fd1Obj, IO_fd_fdID, fd1);
}
}
} else {
/* NET_BindV6() closes both sockets upon a failure */
(*env)->SetObjectField(env, this, psi_fdID, NULL);
(*env)->SetObjectField(env, this, psi_fd1ID, NULL);
}
} else {
rv = NET_WinBind(fd, (struct sockaddr *)&him, len, exclBind);

View File

@ -627,7 +627,7 @@ void dumpAddr (char *str, void *addr) {
* and returns SOCKET_ERROR. Used in NET_BindV6 only.
*/
#define CLOSE_SOCKETS_AND_RETURN { \
#define CLOSE_SOCKETS_AND_RETURN do { \
if (fd != -1) { \
closesocket (fd); \
fd = -1; \
@ -646,7 +646,7 @@ void dumpAddr (char *str, void *addr) {
} \
b->ipv4_fd = b->ipv6_fd = -1; \
return SOCKET_ERROR; \
}
} while(0)
/*
* if ipv6 is available, call NET_BindV6 to bind to the required address/port.