Fixes bug in decode method of ChannelNumberAttribute. Adds method for validating channel value range. Patch by Aakash Garg.

This commit is contained in:
paweldomas 2014-06-09 06:28:32 +00:00
parent 7ccec75461
commit dce1981d7c

View File

@ -13,6 +13,7 @@ import org.ice4j.*;
* channel the TURN client want to send data. * channel the TURN client want to send data.
* *
* @author Sebastien Vincent * @author Sebastien Vincent
* @author Aakash Garg
*/ */
public class ChannelNumberAttribute extends Attribute public class ChannelNumberAttribute extends Attribute
{ {
@ -45,6 +46,7 @@ public class ChannelNumberAttribute extends Attribute
* @param obj the object to compare this attribute with. * @param obj the object to compare this attribute with.
* @return true if the attributes are equal and false otherwise. * @return true if the attributes are equal and false otherwise.
*/ */
@Override
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
if (! (obj instanceof ChannelNumberAttribute) if (! (obj instanceof ChannelNumberAttribute)
@ -71,6 +73,7 @@ public class ChannelNumberAttribute extends Attribute
* for debugging and readability. * for debugging and readability.
* @return this attribute's name. * @return this attribute's name.
*/ */
@Override
public String getName() public String getName()
{ {
return NAME; return NAME;
@ -80,6 +83,7 @@ public class ChannelNumberAttribute extends Attribute
* Returns the length of this attribute's body. * Returns the length of this attribute's body.
* @return the length of this attribute's value (8 bytes). * @return the length of this attribute's value (8 bytes).
*/ */
@Override
public char getDataLength() public char getDataLength()
{ {
return DATA_LENGTH; return DATA_LENGTH;
@ -89,6 +93,7 @@ public class ChannelNumberAttribute extends Attribute
* Returns a binary representation of this attribute. * Returns a binary representation of this attribute.
* @return a binary representation of this attribute. * @return a binary representation of this attribute.
*/ */
@Override
public byte[] encode() public byte[] encode()
{ {
byte binValue[] = new byte[HEADER_LENGTH + DATA_LENGTH]; byte binValue[] = new byte[HEADER_LENGTH + DATA_LENGTH];
@ -118,6 +123,7 @@ public class ChannelNumberAttribute extends Attribute
* @param length the length of the binary array. * @param length the length of the binary array.
* @throws StunException if attrubteValue contains invalid data. * @throws StunException if attrubteValue contains invalid data.
*/ */
@Override
void decodeAttributeBody(byte[] attributeValue, char offset, char length) void decodeAttributeBody(byte[] attributeValue, char offset, char length)
throws StunException throws StunException
{ {
@ -127,7 +133,8 @@ public class ChannelNumberAttribute extends Attribute
} }
channelNumber = channelNumber =
((char)((attributeValue[0] << 8 ) | (attributeValue[1] & 0xFF) )); ((char) ((attributeValue[offset] << 8)
| (attributeValue[offset + 1] & 0xFF)));
} }
/** /**
@ -147,4 +154,18 @@ public class ChannelNumberAttribute extends Attribute
{ {
return channelNumber; return channelNumber;
} }
/**
* Determines if the channelNo is in valid range.
* @param channelNo the channelNo to validate.
* @return true if channnelNo is >= 0x4000.
*/
public static boolean isValidRange(char channelNo)
{
if(channelNo >= 0x4000)
{
return true;
}
return false;
}
} }