From 379e90835304e4c15a82f21dce4f5ff2d2d31fc9 Mon Sep 17 00:00:00 2001
From: Grzegorz Sluja <grzegorz.sluja@iopsys.eu>
Date: Tue, 7 May 2024 15:24:46 +0200
Subject: [PATCH] Fix a crash when Session-ID header is longer than 32 bytes

---
 include/asterisk/cdr.h             | 2 +-
 include/asterisk/stasis_channels.h | 2 +-
 main/channel_internal_api.c        | 2 +-
 res/res_pjsip_session.c            | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/asterisk/cdr.h b/include/asterisk/cdr.h
index 6099fa8ac2..807bb2db83 100644
--- a/include/asterisk/cdr.h
+++ b/include/asterisk/cdr.h
@@ -358,7 +358,7 @@ struct ast_cdr {
 	/*! SessionId */
 	unsigned int sessionId;
 	/*! SIPSessionID */
-	char SIPSessionID[33];
+	char SIPSessionID[128];
 	/*! sipIpAddress */
 	char sipIpAddress[40];
 	/*! farEndIPAddress */
diff --git a/include/asterisk/stasis_channels.h b/include/asterisk/stasis_channels.h
index 5a754f6715..0fbab12adb 100644
--- a/include/asterisk/stasis_channels.h
+++ b/include/asterisk/stasis_channels.h
@@ -158,7 +158,7 @@ struct ast_channel_snapshot {
 	struct varshead *manager_vars;                    /*!< Variables to be appended to manager events */
 	struct varshead *ari_vars;                        /*!< Variables to be appended to ARI events */
 	unsigned int sessionId;                           /*!< SessionId */
-	char SIPSessionID[33];				  /*!< Session-ID */
+	char SIPSessionID[128];                           /*!< Session-ID */
 	char sipIpAddress[40];                            /*!< SIP IP Address */
 	char farEndIPAddress[40];                         /*!< Far End IP Address */
 	unsigned int sipResponseCode;                     /*!< SIP Response Code for Invite */
diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c
index 543919471a..6f1a778da9 100644
--- a/main/channel_internal_api.c
+++ b/main/channel_internal_api.c
@@ -225,7 +225,7 @@ struct ast_channel {
 	struct ast_channel_snapshot *snapshot; /*!< The current up to date snapshot of the channel */
 	struct ast_flags snapshot_segment_flags; /*!< Flags regarding the segments of the snapshot */
 	unsigned int sessionId; /*!< Session Id from SDP for channel */
-	char SIPSessionID[33]; /* SIPSessionID from  Session-ID header */
+	char SIPSessionID[128]; /* SIPSessionID from  Session-ID header */
 	char sipIpAddress[40];  /*!< local IP address that sip client binds to */
 	char farEndIPAddress[40];  /*!< Far End IP Address */
 	unsigned int sipResponseCode; /*!< SIP response Code */
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 551449d190..0a2b2574ad 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -4798,9 +4798,9 @@ static void handle_incoming_response(struct ast_sip_session *session, pjsip_rx_d
 			pjsip_generic_string_hdr *SessionID = NULL;
 			static const pj_str_t headerName = { "Session-ID", 10 };
 			SessionID = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &headerName, NULL);
-			char value[33] = {0};
+			char value[128] = {0};
 			if (SessionID)
-				ast_copy_pj_str(&value, &SessionID->hvalue, pj_strlen(&SessionID->hvalue) + 1);
+				ast_copy_pj_str(&value, &SessionID->hvalue, sizeof(value));
 
 			ast_channel_SIPSessionID_set(session->channel, value);
 		}
-- 
GitLab