Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop when decoding a wrong zero-padded AVP #134

Open
aliqued opened this issue Mar 14, 2018 · 0 comments
Open

Infinite loop when decoding a wrong zero-padded AVP #134

aliqued opened this issue Mar 14, 2018 · 0 comments

Comments

@aliqued
Copy link

aliqued commented Mar 14, 2018

There is a bug in decodeAvp() method of org.jdiameter.client.impl.parser.ElementParser class.

The bug is how the padding bytes are skipped (ElementParser.java lines 299-303):

      if (length % 4 != 0) { 
         for (int i; length % 4 != 0; length += i) { 
           i = (int) in.skip((4 - length % 4)); 
         } 
       } 

If the bytes to skip are greater than the bytes available in the ByteArrayInputStream, the loop for above becomes infinite: in the first iteration in.skip() will return the skipped number of bytes (less than the requested) and in subsequent invocations in.skip() will return 0. So the loop never ends.

My proposed modification is:

        if (length % 4 != 0) {
            int paddingBytes = 4 - length % 4;
            if ((int) in.skip(paddingBytes) < paddingBytes) {
                throw new AvpDataException("Not enough data in buffer (padding bytes)!");
            }
            length += paddingBytes;
        }

As the padding bytes are 1 to 3, this is a very uncommon situation, but it can happens when the wrong padded AVP is the last AVP in the diameter message.

aliqued added a commit to aliqued/jdiameter that referenced this issue Mar 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant