Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(modem): handle nullptr in DTE constructors to prevent invalid access (IDFGH-14688) #768

Conversation

deodatomatheus
Copy link
Contributor

@deodatomatheus deodatomatheus commented Feb 19, 2025

Description

The issue can be reproduced by setting a timeout for waiting for a USB connection (esp_modem_usb_term_config.timeou_ms). When the timeout occurs, the value of primary_term becomes null.

If either primary_term or secondary_term is nullptr, the set_command_callbacks function attempts to access invalid values. For example, in the first line of the function, primary_term->set_read_cb([this](uint8_t *data, size_t len), the program tries to dereference primary_term, leading to a LoadProhibited exception and crashing the application.

To address this, I added a validation check in the DTE constructor to ensure the values are valid. Additionally, I handled the exception in the standard exception handler.

Related

Testing

I test the changes in a ESP32S3.


Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

@CLAassistant
Copy link

CLAassistant commented Feb 19, 2025

CLA assistant check
All committers have signed the CLA.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Feb 19, 2025
@github-actions github-actions bot changed the title fix: handle nullptr in DTE constructors to prevent invalid access fix: handle nullptr in DTE constructors to prevent invalid access (IDFGH-14688) Feb 19, 2025
Copy link
Collaborator

@david-cermak david-cermak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, LGTM!

Could you please just update the commit message prefix -> fix(modem): ...?
(or install the pre-commit hook)

@david-cermak
Copy link
Collaborator

@deodatomatheus Please check also the CI failures, above,
we support a build with exception disabled, as well.

@deodatomatheus deodatomatheus changed the title fix: handle nullptr in DTE constructors to prevent invalid access (IDFGH-14688) fix(modem): handle nullptr in DTE constructors to prevent invalid access (IDFGH-14688) Feb 26, 2025
@deodatomatheus deodatomatheus force-pushed the fix/handle-nullptr-dte-constructors branch from 0f0a4cb to 1a43f17 Compare February 26, 2025 14:30
@deodatomatheus deodatomatheus force-pushed the fix/handle-nullptr-dte-constructors branch from 1a43f17 to 95b5660 Compare February 26, 2025 14:37
@deodatomatheus
Copy link
Contributor Author

deodatomatheus commented Feb 26, 2025

@david-cermak i changed the code to use ESP_MODEM_THROW_IF_FALSE(...) instead of throw std::invalid_argument(...) to support building with exceptions disabled.

Copy link
Collaborator

@david-cermak david-cermak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, LGTM!

@david-cermak david-cermak merged commit 37f84ee into espressif:master Feb 27, 2025
94 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants