From nobody@FreeBSD.org  Wed Mar  2 11:34:53 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 5A0041065677
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  2 Mar 2011 11:34:53 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 4920D8FC1A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  2 Mar 2011 11:34:53 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p22BYqIf079923
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 2 Mar 2011 11:34:52 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p22BYqFL079922;
	Wed, 2 Mar 2011 11:34:52 GMT
	(envelope-from nobody)
Message-Id: <201103021134.p22BYqFL079922@red.freebsd.org>
Date: Wed, 2 Mar 2011 11:34:52 GMT
From: Alex Hayward <xelah-freebsd-pr@xelah.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: False exception throw by NetworkInterface.isUp() (and probably others)
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         155186
>Category:       ports
>Synopsis:       java/openjdk7: False exception throw by NetworkInterface.isUp() (and probably others)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    glewis
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 02 11:40:11 UTC 2011
>Closed-Date:    Fri Jul 08 07:29:59 UTC 2011
>Last-Modified:  Fri Jul  8 07:30:03 UTC 2011
>Originator:     Alex Hayward
>Release:        8.2-PRERELEASE
>Organization:
Ticketable Ltd
>Environment:
FreeBSD magnus.xelah.com 8.2-PRERELEASE FreeBSD 8.2-PRERELEASE #38: Thu Jan 27 12:11:49 GMT 2011     alex@magnus.xelah.com:/usr/obj/usr/src/sys/MAGNUS  amd64

>Description:
NetworkInterface.isUp() can throw a SocketException when there was in
fact no error. This breaks, for example, JGroups.

getFlags in
/usr/ports/java/openjdk7/work/openjdk/jdk/src/solaris/native/java/net/NetworkInterface.c
returns if2.ifr_flags where if2 is a struct ifreq. Callers expect a
negative (int) result on error, a positive one otherwise. ifr_flags is
a short and the top bit can be set of multi-cast capable interfaces.
This remains negative when cast to an int and the caller believes an
error occurred. An exception is thrown based on whatever errno happens
to be.

My JDK port version is openjdk-7.0.122
>How-To-Repeat:
Run this (from JGroups):

import java.net.*;
import java.util.*;

public class test {
    public static void main(String[] argv) throws SocketException {
        InetAddress address=null ;

        try {
            Enumeration intfs=NetworkInterface.getNetworkInterfaces();
            while(intfs.hasMoreElements()) {
                NetworkInterface intf=(NetworkInterface)intfs.nextElement();
                if(intf.isUp()) {
                    //address=getAddress(intf, AddressScope.NON_LOOPBACK) ;
                    //System.err.println(address);
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
}


>Fix:
Change the last statement of getFlags to 'return ((int) if2.ifr_flags) & 0xffff;'

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-ports-bugs 
Responsible-Changed-By: brucec 
Responsible-Changed-When: Wed Mar 2 12:51:29 UTC 2011 
Responsible-Changed-Why:  
Ports PR (java). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=155186 
Responsible-Changed-From-To: freebsd-ports-bugs->glewis 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Wed Mar 2 12:52:35 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=155186 

From: Alex Hayward <xelah-freebsd-pr@xelah.com>
To: bug-followup@FreeBSD.org, xelah-freebsd-pr@xelah.com
Cc:  
Subject: Re: misc/155186: False exception throw by NetworkInterface.isUp()
 (and probably others)
Date: Wed, 2 Mar 2011 12:43:04 +0000 (GMT)

 Ooops, this was meant to be in the 'java' category. Sorry if that's not 
 obvious.
 
   Alex
State-Changed-From-To: open->closed 
State-Changed-By: glewis 
State-Changed-When: Fri Jul 8 07:29:17 UTC 2011 
State-Changed-Why:  
Thanks for the report.  I used a different fix for FreeBSD, but I think your 
change applies well for other BSD variants. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=155186 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/155186: commit references a PR
Date: Fri,  8 Jul 2011 07:28:59 +0000 (UTC)

 glewis      2011-07-08 07:28:46 UTC
 
   FreeBSD ports repository
 
   Modified files:
     java/openjdk7        Makefile 
   Added files:
     java/openjdk7/files  
                          patch-src-solaris-native-java-net-NetworkInterface.c 
   Log:
   . Try harder to make sure the flags returned from getFlags isn't negative,
     since a number of places in the code check for that and assume that it
     means an error occurred.  On FreeBSD, in particular, the value of
     ifr_flags can be negative if multicast is enabled on the socket since
     the possible flags have expanded to fill more than a short.
   
     Instead of blindly promoting ifr_flags to an int, which will preserve
     the sign, we fill the int return value with ifr_flagshigh in the high
     16 bits and ifr_flags in the low 16 bits.
   
   PR:             155186
   Reported by:    Alex Hayward <xelah-freebsd-pr@xelah.com>
   
   Revision  Changes    Path
   1.29      +1 -0      ports/java/openjdk7/Makefile
   1.1       +17 -0     ports/java/openjdk7/files/patch-src-solaris-native-java-net-NetworkInterface.c (new)
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
