Petals BC SOAP

Algorithmic error in function isLocalAddress() from NetworkUtil

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 4.0.4
  • Fix Version/s: 4.0.5, 4.1
  • Component/s: None
  • Security Level: Public
  • Description:
    Hide

    In the current code, the value of 'result' can be overwritten by subsequent non-local addresses. Some 'true' result can be lost.

    I suggest the following patch:

    Index: src/main/java/org/ow2/petals/binding/soap/util/NetworkUtil.java
    ===================================================================
    --- src/main/java/org/ow2/petals/binding/soap/util/NetworkUtil.java	(revision 16340)
    +++ src/main/java/org/ow2/petals/binding/soap/util/NetworkUtil.java	(working copy)
    @@ -129,22 +129,23 @@
          * @return
          */
         public static boolean isLocalAddress(InetAddress address) {
    -        boolean result = false;
             if (address != null) {
                 try {
                     Enumeration<NetworkInterface> itfs = NetworkInterface.getNetworkInterfaces();
                     while (itfs.hasMoreElements()) {
                         NetworkInterface itf = itfs.nextElement();
                         Enumeration<InetAddress> iaenum = itf.getInetAddresses();
    -                    while (iaenum.hasMoreElements() && !result) {
    +                    while (iaenum.hasMoreElements()) {
                             InetAddress ia = iaenum.nextElement();
    -                        result = ia.equals(address);
    +                        if (ia.equals(address)) {
    +							return true;
    +						}
                         }
                     }
                 } catch (SocketException e) {
                 }
             }
    -        return result;
    +        return false;
         }
     
         /**

    By the way, the management of SocketException is still problematic, because it can occur before every network interface has been scanned and make isLocalAddress() return false while it should have returned true.

    Show
    In the current code, the value of 'result' can be overwritten by subsequent non-local addresses. Some 'true' result can be lost. I suggest the following patch:
    Index: src/main/java/org/ow2/petals/binding/soap/util/NetworkUtil.java
    ===================================================================
    --- src/main/java/org/ow2/petals/binding/soap/util/NetworkUtil.java	(revision 16340)
    +++ src/main/java/org/ow2/petals/binding/soap/util/NetworkUtil.java	(working copy)
    @@ -129,22 +129,23 @@
          * @return
          */
         public static boolean isLocalAddress(InetAddress address) {
    -        boolean result = false;
             if (address != null) {
                 try {
                     Enumeration<NetworkInterface> itfs = NetworkInterface.getNetworkInterfaces();
                     while (itfs.hasMoreElements()) {
                         NetworkInterface itf = itfs.nextElement();
                         Enumeration<InetAddress> iaenum = itf.getInetAddresses();
    -                    while (iaenum.hasMoreElements() && !result) {
    +                    while (iaenum.hasMoreElements()) {
                             InetAddress ia = iaenum.nextElement();
    -                        result = ia.equals(address);
    +                        if (ia.equals(address)) {
    +							return true;
    +						}
                         }
                     }
                 } catch (SocketException e) {
                 }
             }
    -        return result;
    +        return false;
         }
     
         /**
    By the way, the management of SocketException is still problematic, because it can occur before every network interface has been scanned and make isLocalAddress() return false while it should have returned true.
  • Environment:
    All

Activity

Transition Status Change Time Execution Times Last Executer Last Execution Date
New New Open Open
16h 57m
1
noddoux
Fri, 26 Nov 2010 - 09:46:46 +0100
Open Open In Progress In Progress
7s
1
noddoux
Fri, 26 Nov 2010 - 09:46:53 +0100
In Progress In Progress Resolved Resolved
3d 2h 32m
1
noddoux
Mon, 29 Nov 2010 - 12:18:58 +0100

People

Dates

  • Created:
    Thu, 25 Nov 2010 - 16:49:04 +0100
    Updated:
    Thu, 16 Feb 2012 - 17:06:34 +0100
    Resolved:
    Mon, 29 Nov 2010 - 12:18:58 +0100