[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] rtp: Accept CRLF delimiters in SDP as required by RFC 4566

Tanu Kaskinen (@tanuk) gitlab at gitlab.freedesktop.org
Mon May 30 18:51:51 UTC 2022



Tanu Kaskinen pushed to branch master at PulseAudio / pulseaudio


Commits:
b55bcc3d by Igor V. Kovalenko at 2022-05-30T18:43:35+00:00
rtp: Accept CRLF delimiters in SDP as required by RFC 4566

RFC 4566 states that SDP record is terminated with CRLF, and parsers should be
able to accept records terminated with just LF. Pulseaudio only accepts LF here.

Fix this by accepting both CRLF and LF terminators.

- - - - -


3 changed files:

- src/modules/rtp/sap.c
- src/modules/rtp/sdp.c
- src/modules/rtp/sdp.h


Changes:

=====================================
src/modules/rtp/sap.c
=====================================
@@ -213,7 +213,9 @@ int pa_sap_recv(pa_sap_context *c, bool *goodbye) {
     if ((unsigned) size >= sizeof(MIME_TYPE) && pa_streq(e, MIME_TYPE)) {
         e += sizeof(MIME_TYPE);
         size -= (int) sizeof(MIME_TYPE);
-    } else if ((unsigned) size < sizeof(PA_SDP_HEADER)-1 || strncmp(e, PA_SDP_HEADER, sizeof(PA_SDP_HEADER)-1)) {
+    } else if ((unsigned) size < sizeof(PA_SDP_HEADER)-1 || strncmp(e, PA_SDP_HEADER, sizeof(PA_SDP_HEADER)-1)
+            || strcspn(e, "\r\n") != sizeof(PA_SDP_HEADER)-1) {
+        /* SDP header does not start with v=0[\r]\n */
         pa_log_warn("Invalid SDP header.");
         goto fail;
     }


=====================================
src/modules/rtp/sdp.c
=====================================
@@ -73,7 +73,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"
@@ -130,17 +130,29 @@ pa_sdp_info *pa_sdp_parse(const char *t, pa_sdp_info *i, int is_goodbye) {
     i->salen = 0;
     i->payload = 255;
 
-    if (!pa_startswith(t, PA_SDP_HEADER)) {
+    if (pa_startswith(t, PA_SDP_HEADER)) {
+        t += sizeof(PA_SDP_HEADER) - 1;
+
+        /* CR delimiter is optional */
+        if (*t == '\r')
+            t++;
+
+        /* LF delimiter is mandatory */
+        if (*t == '\n')
+            t++;
+        else {
+            pa_log("Failed to parse SDP data: missing header record terminator LF.");
+            goto fail;
+        }
+    } else {
         pa_log("Failed to parse SDP data: invalid header.");
         goto fail;
     }
 
-    t += sizeof(PA_SDP_HEADER)-1;
-
     while (*t) {
         size_t l;
 
-        l = strcspn(t, "\n");
+        l = strcspn(t, "\r\n");
 
         if (l <= 2) {
             pa_log("Failed to parse SDP data: line too short: >%s<.", t);
@@ -240,8 +252,17 @@ pa_sdp_info *pa_sdp_parse(const char *t, pa_sdp_info *i, int is_goodbye) {
 
         t += l;
 
+        /* CR delimiter is optional */
+        if (*t == '\r')
+            t++;
+
+        /* LF delimiter is mandatory */
         if (*t == '\n')
             t++;
+        else {
+            pa_log("Failed to parse SDP data: missing record terminator LF.");
+            goto fail;
+        }
     }
 
     if (!i->origin || (!is_goodbye && (!i->salen || i->payload > 127 || !ss_valid || port == 0))) {


=====================================
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;



View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/b55bcc3df33be268a59aa8b8263fa6713487e182

-- 
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/b55bcc3df33be268a59aa8b8263fa6713487e182
You're receiving this email because of your account on gitlab.freedesktop.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20220530/8ad90610/attachment-0001.htm>


More information about the pulseaudio-commits mailing list