[PATCH 1/3] rtp: Support CR/LF separators in SDP packets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



According to RFC 4566 section 5: The sequence CRLF (0x0d0a) is used to
end a record, although parsers SHOULD be tolerant and also accept records
terminated with a single newline character.

Right now, only LF-separated records are understood, so it's clearly a
bug. This has already been spotted here[1] and here[2] but never properly
fixed.

Let's fix the parser to accept both. The writer should also be fixed to
always send CR/LF, but this would trigger backward compatibility issues
with existing PA installations.

[1] https://lists.freedesktop.org/archives/pulseaudio-discuss/2012-July/014183.html
[2] https://lists.freedesktop.org/archives/pulseaudio-discuss/2013-December/019626.html

Signed-off-by: Cédric Schieli <cschieli at gmail.com>
---
 src/modules/rtp/sdp.c | 13 ++++++++++++-
 src/modules/rtp/sdp.h |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/modules/rtp/sdp.c b/src/modules/rtp/sdp.c
index 14953cf..c928c2f 100644
--- a/src/modules/rtp/sdp.c
+++ b/src/modules/rtp/sdp.c
@@ -64,7 +64,7 @@ char *pa_sdp_build(int af, const void *src, const void *dst, const char *name, u
     pa_assert_se(inet_ntop(af, dst, buf_dst, sizeof(buf_dst)));
 
     return pa_sprintf_malloc(
-            PA_SDP_HEADER
+            PA_SDP_HEADER "\n"
             "o=%s %lu 0 IN %s %s\n"
             "s=%s\n"
             "c=IN %s %s\n"
@@ -133,11 +133,20 @@ pa_sdp_info *pa_sdp_parse(const char *t, pa_sdp_info *i, int is_goodbye) {
     }
 
     t += sizeof(PA_SDP_HEADER)-1;
+    if (*t == '\r')
+        t++;
+    if (*t != '\n') {
+        pa_log("Failed to parse SDP data: invalid header.");
+        goto fail;
+    }
+    t++;
 
     while (*t) {
         size_t l;
 
         l = strcspn(t, "\n");
+	if (t[l-1] == '\r')
+	    l--;
 
         if (l <= 2) {
             pa_log("Failed to parse SDP data: line too short: >%s<.", t);
@@ -234,6 +243,8 @@ pa_sdp_info *pa_sdp_parse(const char *t, pa_sdp_info *i, int is_goodbye) {
 
         t += l;
 
+        if (*t == '\r')
+            t++;
         if (*t == '\n')
             t++;
     }
diff --git a/src/modules/rtp/sdp.h b/src/modules/rtp/sdp.h
index 5e9b8fe..46c559a 100644
--- a/src/modules/rtp/sdp.h
+++ b/src/modules/rtp/sdp.h
@@ -26,7 +26,7 @@
 
 #include <pulse/sample.h>
 
-#define PA_SDP_HEADER "v=0\n"
+#define PA_SDP_HEADER "v=0"
 
 typedef struct pa_sdp_info {
     char *origin;
-- 
2.7.3



[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux