Bug found in SDPAnnounceParser
Andreas Piirimets <[email protected]>
| Newsgroups | gmane.comp.voip.nist-sip |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I found a bug in SDPAnnounceParser.java. If someone calls you with an SDP
containing only "\n" in the end of the rows, SDPAnnounceParser will not be
able to parse it correctly. I know it's not RFC compatible to use only \n, but
you never know when you connect to strange SDP implementations.
A "\r\n" is added to the SDP, this confuses the parser. Instead of
adding "\r\n", we should first check the SDP and see how lines are ended (in
my case "\n") and then add the proper ending ("\n" in this case).
See fix below. There are for sure better ways to do the fix if you really want
to make it slimmer.
Best regards,
Andreas Piirimets
Omnitor
--
Index: SDPAnnounceParser.java
===================================================================
RCS file: /cvs/jain-sip/src/gov/nist/javax/sdp/parser/SDPAnnounceParser.java,v
retrieving revision 1.7
diff -u -r1.7 SDPAnnounceParser.java
--- SDPAnnounceParser.java 13 Jul 2006 09:02:37 -0000 1.7
+++ SDPAnnounceParser.java 27 Sep 2006 09:24:58 -0000
@@ -57,8 +57,34 @@
// to be parsed. Bruno Konik noticed this bug.
if (message == null ) return;
sdpMessage = new Vector();
+
+ // Fix by Omnitor (Andreas & Benjamin) 2006-09-27
+ int ix1 = message.indexOf("\n", start);
+ int ix2 = message.indexOf("\r", start);
+ String endingSeparator;
+ if (ix1>0 && ix2<0) {
+ // Only "\n"
+ endingSeparator = "\n";
+ }
+ else if (ix1<0 && ix2>0) {
+ // Only "\r"
+ endingSeparator = "\r";
+ }
+ else if (ix1<ix2) {
+ // "\n\r"
+ endingSeparator = "\n\r";
+ }
+ else {
+ // "\r\n"
+ endingSeparator = "\r\n";
+ }
+ String sdpAnnounce = message.trim() + endingSeparator;
+ // End of fix
+
// Strip off leading and trailing junk.
- String sdpAnnounce = message.trim() + "\r\n";
+ // Row below is removed by Omnitor 2006-09-27
(Andreas&Benjamin)
+ //String sdpAnnounce = message.trim() + "\r\n";
+
// Bug fix by Andreas Bystrom.
while (start < sdpAnnounce.length()) {
int add = 0;