Skip to content
Snippets Groups Projects
Commit 11c1afb6 authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud
Browse files

sipaccountbase: avoid use after free for publishedIpAddress_

Change-Id: I2b6b5c81798b6fb9fbd977e64705bbd2d3364d27
parent 1b6ab3df
Branches
No related tags found
No related merge requests found
...@@ -446,8 +446,9 @@ void SIPAccount::serialize(YAML::Emitter &out) const ...@@ -446,8 +446,9 @@ void SIPAccount::serialize(YAML::Emitter &out) const
void SIPAccount::usePublishedAddressPortInVIA() void SIPAccount::usePublishedAddressPortInVIA()
{ {
via_addr_.host.ptr = (char *) publishedIpAddress_.c_str(); publishedIpStr_ = publishedIp_.toString();
via_addr_.host.slen = publishedIpAddress_.size(); via_addr_.host.ptr = (char *) publishedIpStr_.c_str();
via_addr_.host.slen = publishedIpStr_.size();
via_addr_.port = publishedPort_; via_addr_.port = publishedPort_;
} }
...@@ -1413,7 +1414,7 @@ SIPAccount::getContactHeader(pjsip_transport* t) ...@@ -1413,7 +1414,7 @@ SIPAccount::getContactHeader(pjsip_transport* t)
useUPnPAddressPortInVIA(); useUPnPAddressPortInVIA();
JAMI_DBG("Using UPnP address %s and port %d", address.c_str(), port); JAMI_DBG("Using UPnP address %s and port %d", address.c_str(), port);
} else if (not publishedSameasLocal_) { } else if (not publishedSameasLocal_) {
address = publishedIpAddress_; address = publishedIp_.toString();
port = publishedPort_; port = publishedPort_;
JAMI_DBG("Using published address %s and port %d", address.c_str(), port); JAMI_DBG("Using published address %s and port %d", address.c_str(), port);
} else if (stunEnabled_) { } else if (stunEnabled_) {
......
...@@ -782,6 +782,9 @@ class SIPAccount : public SIPAccountBase { ...@@ -782,6 +782,9 @@ class SIPAccount : public SIPAccountBase {
*/ */
pjsip_host_port via_addr_; pjsip_host_port via_addr_;
// This is used at runtime . Mainly by SIPAccount::usePublishedAddressPortInVIA()
std::string publishedIpStr_ {};
/** /**
* Temporary storage for getUPnPIpAddress().toString() * Temporary storage for getUPnPIpAddress().toString()
* Used only by useUPnPAddressPortInVIA(). * Used only by useUPnPAddressPortInVIA().
......
...@@ -268,7 +268,6 @@ SIPAccountBase::getAccountDetails() const ...@@ -268,7 +268,6 @@ SIPAccountBase::getAccountDetails() const
a.emplace(Conf::CONFIG_PUBLISHED_PORT, std::to_string(publishedPort_)); a.emplace(Conf::CONFIG_PUBLISHED_PORT, std::to_string(publishedPort_));
a.emplace(Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal_ ? TRUE_STR : FALSE_STR); a.emplace(Conf::CONFIG_PUBLISHED_SAMEAS_LOCAL, publishedSameasLocal_ ? TRUE_STR : FALSE_STR);
a.emplace(Conf::CONFIG_PUBLISHED_ADDRESS, publishedIpAddress_); a.emplace(Conf::CONFIG_PUBLISHED_ADDRESS, publishedIpAddress_);
a.emplace(Conf::CONFIG_STUN_ENABLE, stunEnabled_ ? TRUE_STR : FALSE_STR); a.emplace(Conf::CONFIG_STUN_ENABLE, stunEnabled_ ? TRUE_STR : FALSE_STR);
a.emplace(Conf::CONFIG_STUN_SERVER, stunServer_); a.emplace(Conf::CONFIG_STUN_SERVER, stunServer_);
a.emplace(Conf::CONFIG_TURN_ENABLE, turnEnabled_ ? TRUE_STR : FALSE_STR); a.emplace(Conf::CONFIG_TURN_ENABLE, turnEnabled_ ? TRUE_STR : FALSE_STR);
...@@ -431,9 +430,8 @@ void ...@@ -431,9 +430,8 @@ void
SIPAccountBase::setPublishedAddress(const IpAddr& ip_addr) SIPAccountBase::setPublishedAddress(const IpAddr& ip_addr)
{ {
publishedIp_ = ip_addr; publishedIp_ = ip_addr;
publishedIpAddress_ = ip_addr.toString();
JAMI_DBG("[Account %s] Using public address %s", getAccountID().c_str(), JAMI_DBG("[Account %s] Using public address %s", getAccountID().c_str(),
publishedIpAddress_.c_str()); publishedIp_.toString().c_str());
} }
} // namespace jami } // namespace jami
...@@ -353,6 +353,7 @@ protected: ...@@ -353,6 +353,7 @@ protected:
*/ */
IpAddr publishedIp_ {}; IpAddr publishedIp_ {};
// This will be stored in the configuration
std::string publishedIpAddress_ {}; std::string publishedIpAddress_ {};
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment