jsip
  1. jsip
  2. JSIP-413

Concurrency issue within MessageChannel.java when using IPv6 addresses

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      The implementation of the two getKey() methods in gov.nist.javax.sip.stack.MessageChannel.java can cause a concurrency issue.
      The method
      "public static String getKey(InetAddress inetAddr, int port, String transport)"
      will return a string not containing the brackets [], e.g. TCP:fd80::bdff:78b1:c4a8:26:5060.
      The other method
      "public static String getKey(HostPort hostPort, String transport)"
      will return a string which contains brackets [], e.g. TCP:[fd80::bdff:78b1:c4a8:26]:5060

      Both methods are used by the TCPMessageProcessor and TLSMessageProcessor to create the TCPMessageChannel/TLSMessageChannel on demand.
      Due to this problem two MessageProcessors will be created for the same key (the same remote address).
      Together with a message channel a receiver thread will be created. So you will get the situation that you have two different receiver threads receiving messages from one socket. This will cause severe problems when a SIP message is received in two parts with two different TCP packets. The two received TCP packets may be handled by the two threads concurrently. It occurs, that the second half of the SIP message is handled before the first half which causes parser errors.

      My suggestion is to remove potential brackets in both methods to guarantee to get the same key returned by both methods.
      I've added a patch file for this.

        Activity

        Hide
        mranga added a comment -

        r1998
        Thanks. Please format patch from the root of the source tree!

        Show
        mranga added a comment - r1998 Thanks. Please format patch from the root of the source tree!
        Hide
        Alex Saveliev added a comment -

        proposed patch is incorrect, it causes:

        java.util.regex.PatternSyntaxException: Unclosed character class near index 1
        []
        ^
        at java.util.regex.Pattern.error(Unknown Source)
        at java.util.regex.Pattern.clazz(Unknown Source)
        at java.util.regex.Pattern.sequence(Unknown Source)
        at java.util.regex.Pattern.expr(Unknown Source)
        at java.util.regex.Pattern.compile(Unknown Source)
        at java.util.regex.Pattern.<init>(Unknown Source)
        at java.util.regex.Pattern.compile(Unknown Source)
        at java.lang.String.replaceAll(Unknown Source)
        at gov.nist.javax.sip.stack.MessageChannel.getKey(MessageChannel.java:313)
        at gov.nist.javax.sip.stack.TLSMessageChannel.<init>(TLSMessageChannel.java:137)
        at gov.nist.javax.sip.stack.TLSMessageProcessor.run(TLSMessageProcessor.java:195)
        at java.lang.Thread.run(Unknown Source)

        Show
        Alex Saveliev added a comment - proposed patch is incorrect, it causes: java.util.regex.PatternSyntaxException: Unclosed character class near index 1 [] ^ at java.util.regex.Pattern.error(Unknown Source) at java.util.regex.Pattern.clazz(Unknown Source) at java.util.regex.Pattern.sequence(Unknown Source) at java.util.regex.Pattern.expr(Unknown Source) at java.util.regex.Pattern.compile(Unknown Source) at java.util.regex.Pattern.<init>(Unknown Source) at java.util.regex.Pattern.compile(Unknown Source) at java.lang.String.replaceAll(Unknown Source) at gov.nist.javax.sip.stack.MessageChannel.getKey(MessageChannel.java:313) at gov.nist.javax.sip.stack.TLSMessageChannel.<init>(TLSMessageChannel.java:137) at gov.nist.javax.sip.stack.TLSMessageProcessor.run(TLSMessageProcessor.java:195) at java.lang.Thread.run(Unknown Source)
        Hide
        mranga added a comment -

        Corrected in r1999.

        Show
        mranga added a comment - Corrected in r1999.
        Hide
        deruelle_jean added a comment -

        Ranga r1999 was still failing. I fixed the code in r2000 to make sure the regex is correct.

        Show
        deruelle_jean added a comment - Ranga r1999 was still failing. I fixed the code in r2000 to make sure the regex is correct.
        Hide
        fre added a comment -

        Thanks for fixing it. I apologize for any inconvenience my patch has caused.
        It was late in the evening and I've changed the patch code a few minutes before attaching it here without having tested it sufficiently. Sorry!

        I've always loaded the sources from the maven sources-jar. Therefore my patches are incorrect.
        From now on I'll use the SVN sources.

        Show
        fre added a comment - Thanks for fixing it. I apologize for any inconvenience my patch has caused. It was late in the evening and I've changed the patch code a few minutes before attaching it here without having tested it sufficiently. Sorry! I've always loaded the sources from the maven sources-jar. Therefore my patches are incorrect. From now on I'll use the SVN sources.

          People

          • Assignee:
            Unassigned
            Reporter:
            fre
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: