changeset 10479:c494138f3561

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
author msheppar
date Tue, 27 Jan 2015 23:35:04 +0000
parents 2d38ef4e9145
children 2210d14a72bd
files src/windows/native/java/net/DualStackPlainDatagramSocketImpl.c src/windows/native/java/net/DualStackPlainSocketImpl.c src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c src/windows/native/java/net/TwoStacksPlainSocketImpl.c src/windows/native/java/net/net_util_md.c
diffstat 5 files changed, 36 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/java/net/DualStackPlainDatagramSocketImpl.c	Mon Jan 26 22:45:35 2015 +0300
+++ b/src/windows/native/java/net/DualStackPlainDatagramSocketImpl.c	Tue Jan 27 23:35:04 2015 +0000
@@ -462,7 +462,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",
@@ -482,7 +482,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/src/windows/native/java/net/DualStackPlainSocketImpl.c	Mon Jan 26 22:45:35 2015 +0300
+++ b/src/windows/native/java/net/DualStackPlainSocketImpl.c	Tue Jan 27 23:35:04 2015 +0000
@@ -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/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c	Mon Jan 26 22:45:35 2015 +0300
+++ b/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c	Tue Jan 27 23:35:04 2015 +0000
@@ -335,6 +335,8 @@
     struct sockaddr_in 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",
@@ -617,7 +621,7 @@
     }
     fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
 
-    memset(&addr, 0, len);
+    memset((char *)&addr, 0, len);
     connect(fd, (struct sockaddr *)&addr, len);
 
     /*
@@ -625,7 +629,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);
     }
@@ -655,8 +659,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");
@@ -1444,7 +1449,7 @@
     } else if (n < 0) {
         NET_ThrowCurrent(env, "Datagram receive failed");
     } else {
-        int port;
+        int port = 0;
         jobject packetAddress;
 
         /*
@@ -1822,11 +1827,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);
 
@@ -2193,7 +2198,7 @@
     int level, optname, optlen;
     union {
         int i;
-    } optval;
+    } optval = {0};
     int ipv6_supported = ipv6_available();
 
     fd = getFD(env, this);
@@ -2444,12 +2449,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/src/windows/native/java/net/TwoStacksPlainSocketImpl.c	Mon Jan 26 22:45:35 2015 +0300
+++ b/src/windows/native/java/net/TwoStacksPlainSocketImpl.c	Tue Jan 27 23:35:04 2015 +0000
@@ -208,6 +208,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);
@@ -400,7 +401,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 */
@@ -843,12 +844,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
      */
@@ -1009,17 +1011,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");
@@ -1043,6 +1045,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/src/windows/native/java/net/net_util_md.c	Mon Jan 26 22:45:35 2015 +0300
+++ b/src/windows/native/java/net/net_util_md.c	Tue Jan 27 23:35:04 2015 +0000
@@ -389,8 +389,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) {
@@ -481,7 +481,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);
@@ -502,7 +502,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) {
@@ -532,8 +532,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) {