]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
pjsip_configuration: Ensure s= and o= lines in SDP are never empty
authorAlexis Hadjisotiriou <ah@gilawa.com>
Fri, 30 Jan 2026 08:36:23 +0000 (08:36 +0000)
committergithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Thu, 26 Feb 2026 14:08:01 +0000 (14:08 +0000)
According to RFC 8866 (Section 5.2), the Session Name (s=) field and
the username part of origin (o=) are both mandatory and cannot be
empty. If a session has no name, or no username part of origin, the
RFC recommends using a single dash (-) as a placeholder.

This fix ensures that if the session name or the username part of
origin length is zero , it defaults to -.

Fixes: #1524
res/res_pjsip/pjsip_config.xml
res/res_pjsip/pjsip_configuration.c

index 270f79049c75f6fca88709206f79e5af47454005..eb78ac32b1019d5db75de275c08e53be6e4047f9 100644 (file)
                                                <version>12.0.0</version>
                                        </since>
                                        <synopsis>String placed as the username portion of an SDP origin (o=) line.</synopsis>
+                                       <description><para>
+                                               The username portion of an SDP origin to be used in the SDP 'o=' line.
+                                               Note: If this option is left empty or set only to whitespace, it will
+                                               automatically default to a hyphen ('-') to ensure compliance
+                                               with RFC 8866.
+                                       </para></description>
                                </configOption>
                                <configOption name="sdp_session" default="Asterisk">
                                        <since>
                                                <version>12.0.0</version>
                                        </since>
                                        <synopsis>String used for the SDP session (s=) line.</synopsis>
+                                       <description><para>
+                                               The session name to be used in the SDP 's=' line.
+                                               Note: If this option is left empty or set only to whitespace, it will
+                                               automatically default to a hyphen ('-') to ensure compliance
+                                               with RFC 8866.
+                               </para></description>
                                </configOption>
                                <configOption name="tos_audio">
                                        <since>
index e23cc7191669be1cbb76c2fdd18dfad1bf16512b..cfc14560045750cd9db98e598d65d7733e1a2044 100644 (file)
@@ -1650,6 +1650,18 @@ static int sip_endpoint_apply_handler(const struct ast_sorcery *sorcery, void *o
                return -1;
        }
 
+       if (ast_strlen_zero(endpoint->media.sdpsession) || !*ast_skip_blanks(endpoint->media.sdpsession)) {
+               ast_log(LOG_WARNING, "SDP session was set to empty on endpoint '%s'. Not permitted as per RFC8866. SDP session set to '-'. \n",
+                       ast_sorcery_object_get_id(endpoint));
+               ast_string_field_set(endpoint, media.sdpsession, "-");
+       }
+
+       if (ast_strlen_zero(endpoint->media.sdpowner) || *ast_skip_nonblanks(ast_skip_blanks(endpoint->media.sdpowner))) {
+               ast_log(LOG_WARNING, "SDP origin username on endpoint '%s' is empty or contains spaces ('%s'). Not permitted as per RFC8866. Setting to '-'.\n",
+                       ast_sorcery_object_get_id(endpoint), endpoint->media.sdpowner);
+               ast_string_field_set(endpoint, media.sdpowner, "-");
+       }
+
        if (ast_rtp_dtls_cfg_validate(&endpoint->media.rtp.dtls_cfg)) {
                return -1;
        }