Skip to content

Commit

Permalink
Merge pull request #768 from deodatomatheus/fix/handle-nullptr-dte-co…
Browse files Browse the repository at this point in the history
…nstructors

fix(modem): handle nullptr in DTE constructors to prevent invalid access (IDFGH-14688)
  • Loading branch information
david-cermak authored Feb 27, 2025
2 parents a22c3da + 95b5660 commit 37f84ee
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions components/esp_modem/src/esp_modem_dte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,53 @@ using namespace esp_modem;

static const size_t dte_default_buffer_size = 1000;

DTE::DTE(const esp_modem_dte_config *config, std::unique_ptr<Terminal> terminal):
buffer(config->dte_buffer_size),
cmux_term(nullptr), primary_term(std::move(terminal)), secondary_term(primary_term),
mode(modem_mode::UNDEF)
DTE::DTE(const esp_modem_dte_config *config, std::unique_ptr<Terminal> terminal)
: buffer(config->dte_buffer_size),
cmux_term(nullptr),
primary_term(std::move(terminal)),
secondary_term(primary_term),
mode(modem_mode::UNDEF)
{
ESP_MODEM_THROW_IF_FALSE(primary_term != nullptr, "Invalid argument: terminal cannot be null");
set_command_callbacks();
}

DTE::DTE(std::unique_ptr<Terminal> terminal):
buffer(dte_default_buffer_size),
cmux_term(nullptr), primary_term(std::move(terminal)), secondary_term(primary_term),
mode(modem_mode::UNDEF)
DTE::DTE(std::unique_ptr<Terminal> terminal)
: buffer(dte_default_buffer_size),
cmux_term(nullptr),
primary_term(std::move(terminal)),
secondary_term(primary_term),
mode(modem_mode::UNDEF)
{
ESP_MODEM_THROW_IF_FALSE(primary_term != nullptr, "Invalid argument: terminal cannot be null");
set_command_callbacks();
}

DTE::DTE(const esp_modem_dte_config *config, std::unique_ptr<Terminal> t, std::unique_ptr<Terminal> s):
buffer(config->dte_buffer_size),
cmux_term(nullptr), primary_term(std::move(t)), secondary_term(std::move(s)),
mode(modem_mode::DUAL_MODE)
DTE::DTE(const esp_modem_dte_config *config, std::unique_ptr<Terminal> t, std::unique_ptr<Terminal> s)
: buffer(config->dte_buffer_size),
cmux_term(nullptr),
primary_term(std::move(t)),
secondary_term(std::move(s)),
mode(modem_mode::DUAL_MODE)
{
ESP_MODEM_THROW_IF_FALSE(primary_term != nullptr, "Invalid argument: primary terminal cannot be null");
ESP_MODEM_THROW_IF_FALSE(secondary_term != nullptr, "Invalid argument: secondary terminal cannot be null");
set_command_callbacks();
}

DTE::DTE(std::unique_ptr<Terminal> t, std::unique_ptr<Terminal> s):
buffer(dte_default_buffer_size),
cmux_term(nullptr), primary_term(std::move(t)), secondary_term(std::move(s)),
mode(modem_mode::DUAL_MODE)
DTE::DTE(std::unique_ptr<Terminal> t, std::unique_ptr<Terminal> s)
: buffer(dte_default_buffer_size),
cmux_term(nullptr),
primary_term(std::move(t)),
secondary_term(std::move(s)),
mode(modem_mode::DUAL_MODE)
{
ESP_MODEM_THROW_IF_FALSE(primary_term != nullptr, "Invalid argument: primary terminal cannot be null");
ESP_MODEM_THROW_IF_FALSE(secondary_term != nullptr, "Invalid argument: secondary terminal cannot be null");
set_command_callbacks();
}


void DTE::set_command_callbacks()
{
primary_term->set_read_cb([this](uint8_t *data, size_t len) {
Expand Down

0 comments on commit 37f84ee

Please sign in to comment.