Skip to content
Snippets Groups Projects
Commit f4742909 authored by Guillaume Roguez's avatar Guillaume Roguez
Browse files

ice: prevent nullptr access to non-initalized transport

Refs #72663

Change-Id: Ic3e5f60ce14e55957fafd738df40bc811c5baac9
parent 2e9bcc05
No related branches found
No related tags found
No related merge requests found
...@@ -257,6 +257,11 @@ bool ...@@ -257,6 +257,11 @@ bool
IceTransport::start(const Attribute& rem_attrs, IceTransport::start(const Attribute& rem_attrs,
const std::vector<IceCandidate>& rem_candidates) const std::vector<IceCandidate>& rem_candidates)
{ {
if (not isInitialized()) {
RING_ERR("ICE: not initialized transport");
return false;
}
// pj_ice_strans_start_ice crashes if remote candidates array is empty // pj_ice_strans_start_ice crashes if remote candidates array is empty
if (rem_candidates.empty()) { if (rem_candidates.empty()) {
RING_ERR("ICE start failed: no remote candidates"); RING_ERR("ICE start failed: no remote candidates");
...@@ -334,7 +339,7 @@ IceTransport::start(const std::vector<uint8_t>& rem_data) ...@@ -334,7 +339,7 @@ IceTransport::start(const std::vector<uint8_t>& rem_data)
bool bool
IceTransport::stop() IceTransport::stop()
{ {
if (not pj_ice_strans_has_sess(icest_.get())) { if (not isInitialized()) {
RING_ERR("Session not created yet"); RING_ERR("Session not created yet");
return false; return false;
} }
...@@ -352,7 +357,9 @@ IceTransport::stop() ...@@ -352,7 +357,9 @@ IceTransport::stop()
bool bool
IceTransport::isInitialized() const IceTransport::isInitialized() const
{ {
return pj_ice_strans_has_sess(icest_.get()); if (auto icest = icest_.get())
return pj_ice_strans_has_sess(icest);
return false;
} }
bool bool
...@@ -370,13 +377,13 @@ IceTransport::isCompleted() const ...@@ -370,13 +377,13 @@ IceTransport::isCompleted() const
bool bool
IceTransport::isRunning() const IceTransport::isRunning() const
{ {
return pj_ice_strans_get_state(icest_.get()) == PJ_ICE_STRANS_STATE_RUNNING; return isInitialized() and pj_ice_strans_get_state(icest_.get()) == PJ_ICE_STRANS_STATE_RUNNING;
} }
bool bool
IceTransport::isFailed() const IceTransport::isFailed() const
{ {
return pj_ice_strans_get_state(icest_.get()) == PJ_ICE_STRANS_STATE_FAILED; return isInitialized() and pj_ice_strans_get_state(icest_.get()) == PJ_ICE_STRANS_STATE_FAILED;
} }
IpAddr IpAddr
...@@ -390,8 +397,10 @@ IceTransport::getLocalAddress(unsigned comp_id) const ...@@ -390,8 +397,10 @@ IceTransport::getLocalAddress(unsigned comp_id) const
IpAddr IpAddr
IceTransport::getRemoteAddress(unsigned comp_id) const IceTransport::getRemoteAddress(unsigned comp_id) const
{ {
if (isInitialized()) {
if (auto sess = pj_ice_strans_get_valid_pair(icest_.get(), comp_id+1)) if (auto sess = pj_ice_strans_get_valid_pair(icest_.get(), comp_id+1))
return sess->rcand->addr; return sess->rcand->addr;
}
return {}; return {};
} }
...@@ -651,6 +660,11 @@ IceTransport::setOnRecv(unsigned comp_id, IceRecvCb cb) ...@@ -651,6 +660,11 @@ IceTransport::setOnRecv(unsigned comp_id, IceRecvCb cb)
ssize_t ssize_t
IceTransport::send(int comp_id, const unsigned char* buf, size_t len) IceTransport::send(int comp_id, const unsigned char* buf, size_t len)
{ {
if (not isInitialized()) {
RING_ERR("ICE: not initialized transport");
return -1;
}
register_thread(); register_thread();
auto remote = getRemoteAddress(comp_id); auto remote = getRemoteAddress(comp_id);
if (!remote) { if (!remote) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment