From e507252d898ff7f8128ab130d040cd7edf054723 Mon Sep 17 00:00:00 2001
From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
Date: Wed, 29 Apr 2015 16:36:20 -0400
Subject: [PATCH] sipcall: fix tls details

This patch fixes crash when sipcall getDetails is called too early.

Refs #68196

Change-Id: I06248512687db93c40672dbad09508f3a194bc69
---
 src/sip/sipcall.cpp | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp
index ff5859ae27..77ef419fee 100644
--- a/src/sip/sipcall.cpp
+++ b/src/sip/sipcall.cpp
@@ -964,23 +964,29 @@ std::map<std::string, std::string>
 SIPCall::getDetails() const
 {
     auto details = Call::getDetails();
-    details.emplace(DRing::Call::Details::PEER_HOLDING,          peerHolding_ ? TRUE_STR : FALSE_STR);
+    details.emplace(DRing::Call::Details::PEER_HOLDING,
+                    peerHolding_ ? TRUE_STR : FALSE_STR);
     if (transport_ and transport_->isSecure()) {
         const auto& tlsInfos = transport_->getTlsInfos();
-        auto cipher = pj_ssl_cipher_name(tlsInfos.cipher);
-        if (tlsInfos.cipher and not cipher)
-            RING_WARN("Unknown cipher: %d", tlsInfos.cipher);
-        details.emplace(DRing::TlsTransport::TLS_CIPHER,         cipher ? cipher : "");
-        details.emplace(DRing::TlsTransport::TLS_PEER_CERT,      tlsInfos.peerCert->toString());
-        auto ca = tlsInfos.peerCert->issuer;
-        unsigned n = 0;
-        while (ca) {
-            std::ostringstream name_str;
-            name_str << DRing::TlsTransport::TLS_PEER_CA_ << n++;
-            details.emplace(name_str.str(),                      ca->toString());
-            ca = ca->issuer;
+        const auto& cipher = pj_ssl_cipher_name(tlsInfos.cipher);
+        details.emplace(DRing::TlsTransport::TLS_CIPHER, cipher ? cipher : "");
+        if (tlsInfos.peerCert) {
+            details.emplace(DRing::TlsTransport::TLS_PEER_CERT,
+                            tlsInfos.peerCert->toString());
+            auto ca = tlsInfos.peerCert->issuer;
+            unsigned n = 0;
+            while (ca) {
+                std::ostringstream name_str;
+                name_str << DRing::TlsTransport::TLS_PEER_CA_ << n++;
+                details.emplace(name_str.str(), ca->toString());
+                ca = ca->issuer;
+            }
+            details.emplace(DRing::TlsTransport::TLS_PEER_CA_NUM,
+                            std::to_string(n));
+        } else {
+            details.emplace(DRing::TlsTransport::TLS_PEER_CERT, "");
+            details.emplace(DRing::TlsTransport::TLS_PEER_CA_NUM, "");
         }
-        details.emplace(DRing::TlsTransport::TLS_PEER_CA_NUM,    std::to_string(n));
     }
     return details;
 }
-- 
GitLab