8040810: Uninitialised memory in jdk/src/windows/native/java/net: net_util_md.c, TwoStacksPlainSocketImpl.c, TwoStacksPlainDatagramSocketImpl.c, DualStackPlainSocketImpl.c, DualStackPlainDatagramSocketImpl.c
Summary: explicitly initialze local function variables
Reviewed-by: alanb
--- a/jdk/src/windows/native/java/net/DualStackPlainDatagramSocketImpl.c Wed Jul 16 16:16:32 2014 +0100
+++ b/jdk/src/windows/native/java/net/DualStackPlainDatagramSocketImpl.c Wed Jul 16 20:43:53 2014 +0100
@@ -467,7 +467,7 @@
*/
JNIEXPORT void JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketSetIntOption
(JNIEnv *env, jclass clazz, jint fd , jint cmd, jint value) {
- int level, opt;
+ int level = 0, opt = 0;
if (NET_MapSocketOption(cmd, &level, &opt) < 0) {
JNU_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
@@ -487,7 +487,7 @@
*/
JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketGetIntOption
(JNIEnv *env, jclass clazz, jint fd, jint cmd) {
- int level, opt, result=0;
+ int level = 0, opt = 0, result=0;
int result_len = sizeof(result);
if (NET_MapSocketOption(cmd, &level, &opt) < 0) {
--- a/jdk/src/windows/native/java/net/DualStackPlainSocketImpl.c Wed Jul 16 16:16:32 2014 +0100
+++ b/jdk/src/windows/native/java/net/DualStackPlainSocketImpl.c Wed Jul 16 20:43:53 2014 +0100
@@ -367,8 +367,8 @@
JNIEXPORT void JNICALL Java_java_net_DualStackPlainSocketImpl_setIntOption
(JNIEnv *env, jclass clazz, jint fd, jint cmd, jint value) {
- int level, opt;
- struct linger linger;
+ int level = 0, opt = 0;
+ struct linger linger = {0, 0};
char *parg;
int arglen;
@@ -407,9 +407,9 @@
JNIEXPORT jint JNICALL Java_java_net_DualStackPlainSocketImpl_getIntOption
(JNIEnv *env, jclass clazz, jint fd, jint cmd) {
- int level, opt;
+ int level = 0, opt = 0;
int result=0;
- struct linger linger;
+ struct linger linger = {0, 0};
char *arg;
int arglen;
--- a/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c Wed Jul 16 16:16:32 2014 +0100
+++ b/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c Wed Jul 16 20:43:53 2014 +0100
@@ -335,6 +335,8 @@
SOCKETADDRESS rmtaddr;
int addrlen = sizeof(rmtaddr);
+ memset((char *)&rmtaddr, 0, sizeof(rmtaddr));
+
/*
* A no-op if this OS doesn't support it.
*/
@@ -431,9 +433,11 @@
int ipv6_supported = ipv6_available();
SOCKETADDRESS lcladdr;
- int lcladdrlen;
+ int lcladdrlen = sizeof(lcladdr);
int address;
+ memset((char *)&lcladdr, 0, sizeof(lcladdr));
+
family = getInetAddress_family(env, addressObj);
if (family == IPv6 && !ipv6_supported) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
@@ -614,7 +618,7 @@
}
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
- memset(&addr, 0, len);
+ memset((char *)&addr, 0, len);
connect(fd, (struct sockaddr *)&addr, len);
/*
@@ -622,7 +626,7 @@
* to disable ICMP port unreachable handling here.
*/
if (xp_or_later) {
- DWORD x1, x2; /* ignored result codes */
+ DWORD x1 = 0, x2 = 0; /* ignored result codes */
int t = FALSE;
WSAIoctl(fd,SIO_UDP_CONNRESET,&t,sizeof(t),&x1,sizeof(x1),&x2,0,0);
}
@@ -652,8 +656,9 @@
SOCKETADDRESS rmtaddr;
SOCKETADDRESS *addrp = &rmtaddr;
- int addrlen;
+ int addrlen = 0;
+ memset((char *)&rmtaddr, 0, sizeof(rmtaddr));
if (IS_NULL(packet)) {
JNU_ThrowNullPointerException(env, "null packet");
@@ -1412,7 +1417,7 @@
} else if (n < 0) {
NET_ThrowCurrent(env, "Datagram receive failed");
} else {
- int port;
+ int port = 0;
jobject packetAddress;
/*
@@ -1791,11 +1796,11 @@
jint opt,jobject value) {
int fd=-1, fd1=-1;
- int levelv4, levelv6, optnamev4, optnamev6, optlen;
+ int levelv4 = 0, levelv6 = 0, optnamev4 = 0, optnamev6 = 0, optlen = 0;
union {
int i;
char c;
- } optval;
+ } optval = { 0 };
int ipv6_supported = ipv6_available();
fd = getFD(env, this);
@@ -2162,7 +2167,7 @@
int level, optname, optlen;
union {
int i;
- } optval;
+ } optval = {0};
int ipv6_supported = ipv6_available();
fd = getFD(env, this);
@@ -2413,12 +2418,15 @@
struct ipv6_mreq mname6;
struct in_addr in;
- DWORD ifindex;
+ DWORD ifindex = 0;
int len, family;
int ipv6_supported = ipv6_available();
int cmd ;
+ memset((char *)&in, 0, sizeof(in));
+ memset((char *)&name, 0, sizeof(name));
+
if (IS_NULL(fdObj) && IS_NULL(fd1Obj)) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Socket closed");
--- a/jdk/src/windows/native/java/net/TwoStacksPlainSocketImpl.c Wed Jul 16 16:16:32 2014 +0100
+++ b/jdk/src/windows/native/java/net/TwoStacksPlainSocketImpl.c Wed Jul 16 20:43:53 2014 +0100
@@ -207,6 +207,7 @@
/* The result of the connection */
int connect_res;
+ memset((char *)&him, 0, sizeof(him));
if (!IS_NULL(fdObj)) {
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
@@ -399,7 +400,7 @@
/* fdObj is the FileDescriptor field on this */
jobject fdObj, fd1Obj;
/* fd is an int field on fdObj */
- int fd, fd1, len;
+ int fd, fd1, len = 0;
int ipv6_supported = ipv6_available();
/* family is an int field of iaObj */
@@ -837,12 +838,13 @@
jint cmd, jboolean on,
jobject value) {
int fd, fd1;
- int level, optname, optlen;
+ int level = 0, optname = 0, optlen = 0;
union {
int i;
struct linger ling;
} optval;
+ memset((char *)&optval, 0, sizeof(optval));
/*
* Get SOCKET and check that it hasn't been closed
*/
@@ -1003,17 +1005,17 @@
jint opt, jobject iaContainerObj) {
int fd, fd1;
- int level, optname, optlen;
+ int level = 0, optname = 0, optlen = 0;
union {
int i;
struct linger ling;
} optval;
-
/*
* Get SOCKET and check it hasn't been closed
*/
fd = getFD(env, this);
fd1 = getFD1(env, this);
+ memset((char *)&optval, 0, sizeof(optval));
if (fd < 0 && fd1 < 0) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
@@ -1037,6 +1039,7 @@
jfieldID iaFieldID;
len = sizeof(him);
+ memset((char *)&him, 0, len);
if (fd == -1) {
/* must be an IPV6 only socket. Case where both sockets are != -1
--- a/jdk/src/windows/native/java/net/net_util_md.c Wed Jul 16 16:16:32 2014 +0100
+++ b/jdk/src/windows/native/java/net/net_util_md.c Wed Jul 16 20:43:53 2014 +0100
@@ -386,8 +386,8 @@
NET_SetSockOpt(int s, int level, int optname, const void *optval,
int optlen)
{
- int rv;
- int parg;
+ int rv = 0;
+ int parg = 0;
int plen = sizeof(parg);
if (level == IPPROTO_IP && optname == IP_TOS) {
@@ -478,7 +478,7 @@
* Sets SO_ECLUSIVEADDRUSE if SO_REUSEADDR is not already set.
*/
void setExclusiveBind(int fd) {
- int parg;
+ int parg = 0;
int plen = sizeof(parg);
int rv = 0;
rv = NET_GetSockOpt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&parg, &plen);
@@ -499,7 +499,7 @@
JNIEXPORT int JNICALL
NET_Bind(int s, struct sockaddr *him, int len)
{
- int rv;
+ int rv = 0;
rv = bind(s, him, len);
if (rv == SOCKET_ERROR) {
@@ -529,8 +529,8 @@
JNIEXPORT int JNICALL
NET_SocketClose(int fd) {
- struct linger l;
- int ret;
+ struct linger l = {0, 0};
+ int ret = 0;
int len = sizeof (l);
if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) {
if (l.l_onoff == 0) {