RE: Bug found in SDPAnnounceParser
"Ricardo Borba" <[email protected]>
| Newsgroups | gmane.comp.voip.nist-sip |
|---|---|
| Message-ID | <AF72D46D56403D45AF5441A2D92F867001CF9C2E@server01.NaturalConvergence.com> |
Hi Andreas and others,
I had a similar issue some time ago with an even nastier device sending
mixed "\r" and "\n" EOLs in the same SDP. At one point the original
algorithm (Revision 1.7 2006/07/13 09:02:37) would find a '\r' in the
current line and match it with a '\n' in the very last line, ignoring
everything else in between. That device was a really big mess but we had
no way to change its behavior.
So I decided to write a more strict implementation for the
SDPAnnounceParser constructor that looks a lot like the one that you
wrote but covering these nasty cases:
public SDPAnnounceParser(String message)
{
int start = 0;
String line = null;
// Return trivially if there is no sdp announce message
// to be parsed. Bruno Konik noticed this bug.
if (message == null ) return;
sdpMessage = new Vector();
// Strip off leading and trailing junk.
String sdpAnnounce = message.trim() + "\r\n";
// Bug fix by Andreas Bystrom.
// ** my changes start here **
while (start < sdpAnnounce.length())
{
int lfPos = sdpAnnounce.indexOf("\n", start);
int crPos = sdpAnnounce.indexOf("\r", start);
if (lfPos > 0 && crPos < 0)
{
// there are only "\n" separators
line = sdpAnnounce.substring(start, lfPos);
start = lfPos + 1;
}
else if (lfPos < 0 && crPos > 0)
{
//bug fix: there are only "\r" separators
line = sdpAnnounce.substring(start, crPos);
start = crPos + 1;
}
else if (lfPos > 0 && crPos > 0)
{
// there are "\r\n" or "\n\r" (if exists) separators
if (lfPos > crPos)
{
// assume "\r\n" for now
line = sdpAnnounce.substring(start, crPos);
// Check if the "\r" and "\n" are close together
if (lfPos == crPos + 1)
start = lfPos + 1; // "\r\n"
else
start = crPos + 1; // "\r" followed by the next record and a
"\n" further away
}
else
{
// assume "\n\r" for now
line = sdpAnnounce.substring(start, lfPos);
// Check if the "\n" and "\r" are close together
if (crPos == lfPos + 1)
start = crPos + 1; // "\n\r"
else
start = lfPos + 1; // "\n" followed by the next record and a
"\r" further away
}
}
else if (lfPos < 0 && crPos < 0) // end
break;
// ** my changes end here **
sdpMessage.addElement(line);
}
}
Would this cover you case as well?
Regards,
Ricardo