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

Christophe DENEUX made changes - Fri, 26 Nov 2010 - 08:25:59 +0100
Field Original Value New Value
Priority Blocker [ 1 ]
Description 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.

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:
{code}
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;
     }
 
     /**
{code}


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.

Charles Casadei made changes - Wed, 1 Dec 2010 - 10:39:20 +0100
Link This issue blocks SPVEOLIAE-92 [ SPVEOLIAE-92 ]
Christophe DENEUX made changes - Fri, 30 Sep 2011 - 09:19:30 +0200
Fix Version/s 4.1_4.0 [ 10269 ]
Fix Version/s 4.1 [ 10186 ]
Affects Version/s 4.1 [ 10186 ]
Sébastien Rebiere made changes - Thu, 16 Feb 2012 - 17:06:34 +0100
Fix Version/s 4.1 [ 10186 ]
Fix Version/s 4.1_4.0 [ 10269 ]

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