This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Handle null host in Socket.bind().


This is a problem I noticed while looking at something else.

We are not handling a null host value which should bind to INADDR_ANY. 
We would get a NPE instead.

OK for 4.3 if testing shows no problems?

2008-02-04  David Daney  <ddaney@avtrex.com>

    * gnu/java/net/natPlainSocketImplPosix.cc(bind): Handle null
    host.

Index: gnu/java/net/natPlainSocketImplPosix.cc
===================================================================
--- gnu/java/net/natPlainSocketImplPosix.cc	(revision 132105)
+++ gnu/java/net/natPlainSocketImplPosix.cc	(working copy)
@@ -86,9 +86,14 @@ gnu::java::net::PlainSocketImpl::bind (:
 {
   union SockAddr u;
   struct sockaddr *ptr = (struct sockaddr *) &u.address;
-  jbyteArray haddress = host->addr;
-  jbyte *bytes = elements (haddress);
-  int len = haddress->length;
+  int len = 4;
+  jbyte *bytes = NULL;
+  if (host != NULL)
+    {
+      jbyteArray haddress = host->addr;
+      bytes = elements (haddress);
+      len = haddress->length;
+    }
   int i = 1;
 
   // The following is needed for OS X/PPC, otherwise bind() fails with an

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]