This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[PATCH] Handle null host in Socket.bind().
- From: David Daney <ddaney at avtrex dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: Mon, 04 Feb 2008 19:01:03 -0800
- Subject: [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