From 50b7bc2459080e767aaa24a2bf6b13a2fd90a217 Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Tue, 29 Jul 2025 15:40:59 +0200 Subject: [PATCH] MT#59962 AmSdp::parse(): always check return value When using that, the return value must always be checked, because the parsing itself can indeed fail. Fixes such things as: ** CID 583412: Error handling issues (CHECKED_RETURN) /core/AmB2BSession.cpp: 340 in AmB2BSession::acceptPendingInvite(AmSipRequest *, const AmMimeBody *)() _____________________________________________________________________________________________ *** CID 583412: Error handling issues (CHECKED_RETURN) /core/AmB2BSession.cpp: 340 in AmB2BSession::acceptPendingInvite(AmSipRequest *, const AmMimeBody *)() 334 return; 335 } 336 337 /* port must reflect actual port in SDP offer coming in */ 338 if (sdp) { 339 AmSdp fake_sdp; >>> CID 583412: Error handling issues (CHECKED_RETURN) >>> Calling "parse" without checking return value (as is done elsewhere 12 out of 15 times). 340 fake_sdp.parse((const char *)sdp->getPayload()); 341 desired_port = getMediaPort(fake_sdp); 342 } 343 344 if (desired_port) { 345 ILOG_DLG(L_DBG, "Desired port for fake 200OK is '%d'\n", desired_port); Change-Id: I7bd177a624ebe2df2629863eb31f97f99bd921bb --- apps/sbc/SBCCallLeg.cpp | 8 +++++++- core/AmB2BSession.cpp | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/sbc/SBCCallLeg.cpp b/apps/sbc/SBCCallLeg.cpp index 324aebfd..bd6ff323 100644 --- a/apps/sbc/SBCCallLeg.cpp +++ b/apps/sbc/SBCCallLeg.cpp @@ -1869,7 +1869,13 @@ void SBCCallLeg::createHoldRequest(AmSdp &sdp) // version number in every SDP passing through?) AmMimeBody *s = dlg->established_body.hasContentType(SIP_APPLICATION_SDP); - if (s) sdp.parse((const char*)s->getPayload()); + if (s) { + if (sdp.parse((const char*)s->getPayload())) + { + ILOG_DLG(L_WARN, "Failed to parse SDP.\n"); + return; + } + } if (sdp.media.empty()) { // established SDP is not valid! generate complete fake diff --git a/core/AmB2BSession.cpp b/core/AmB2BSession.cpp index 0be58372..e38573fb 100644 --- a/core/AmB2BSession.cpp +++ b/core/AmB2BSession.cpp @@ -291,7 +291,11 @@ void AmB2BSession::addFakeSDPbasedOnPort(const AmMimeBody *src_sdp, AmMimeBody & /* create fake AmSdp from AmMimeBody */ AmSdp fake_sdp; AmMimeBody fake_mimebody; - fake_sdp.parse((const char *)src_sdp->getPayload()); + if (fake_sdp.parse((const char *)src_sdp->getPayload())) + { + ILOG_DLG(L_WARN, "Failed to parse SDP.\n"); + return; + } for (auto it = fake_sdp.media.begin(); it != fake_sdp.media.end(); ++it) { @@ -337,8 +341,13 @@ void AmB2BSession::acceptPendingInvite(AmSipRequest *invite, const AmMimeBody *s /* port must reflect actual port in SDP offer coming in */ if (sdp) { AmSdp fake_sdp; - fake_sdp.parse((const char *)sdp->getPayload()); - desired_port = getMediaPort(fake_sdp); + if (fake_sdp.parse((const char *)sdp->getPayload())) + { + ILOG_DLG(L_WARN, "Failed to parse SDP.\n"); + } + else { + desired_port = getMediaPort(fake_sdp); + } } if (desired_port) {