From fad66c072a3b780924ed4cf048000fd7c7434441 Mon Sep 17 00:00:00 2001
From: Simon Morlat <simon.morlat@linphone.org>
Date: Wed, 18 Dec 2024 06:02:22 +0100
Subject: [PATCH] Fix crash when linphone_call_get_replaced_call() is used in
 OutgoingInit state.

---
 src/conference/session/call-session.cpp | 1 +
 src/sal/call-op.cpp                     | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/conference/session/call-session.cpp b/src/conference/session/call-session.cpp
index 0039c552fd..8155a55294 100644
--- a/src/conference/session/call-session.cpp
+++ b/src/conference/session/call-session.cpp
@@ -1997,6 +1997,7 @@ const string &CallSession::getRemoteUserAgent() const {
 
 shared_ptr<CallSession> CallSession::getReplacedCallSession() const {
 	L_D();
+	if (!d->op) return nullptr;
 	SalOp *replacedOp = d->op->getReplaces();
 	if (!replacedOp) return nullptr;
 	return static_cast<CallSession *>(replacedOp->getUserPointer())->getSharedFromThis();
diff --git a/src/sal/call-op.cpp b/src/sal/call-op.cpp
index d159497c96..52b0965153 100644
--- a/src/sal/call-op.cpp
+++ b/src/sal/call-op.cpp
@@ -1627,7 +1627,7 @@ SalCallOp *SalCallOp::getReplaces() const {
 	auto dialog = belle_sip_provider_find_dialog(mRoot->mProvider, belle_sip_header_replaces_get_call_id(mReplaces),
 	                                             to_tag, from_tag);
 
-	if (!dialog && (to_tag == NULL || strcmp(belle_sip_header_replaces_get_to_tag(mReplaces), "0") == 0)) {
+	if (!dialog && (to_tag == NULL || strcmp(to_tag, "0") == 0)) {
 		// even if not described in rfc3891, in case of very early network switch at caller side, we might receive a
 		// replace header without to-tag. Give a chance to find the early dialog
 		dialog = belle_sip_provider_find_dialog_with_remote_tag(mRoot->mProvider,
-- 
GitLab