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

nsh: check nsh_consolemain return value #22012

Merged
merged 1 commit into from
Aug 29, 2023
Merged

Conversation

niklaut
Copy link
Contributor

@niklaut niklaut commented Aug 28, 2023

Solved Problem

Starting a new console allocates memory dynamically, which can fail, but the pointer wasn't checked and caused a hardfault on heap exhaustion.
This adds the check and returns a error message if the console fails to allocate.

For details on the hardfault see: PX4/NuttX-apps#18

Changelog Entry

For release notes:

Bugfix Handle out-of-memory condition when starting a MAVLINK shell.

Test coverage

Tested manually via GDB by forcing zalloc to return NULL for the test case. Reproduces the crash reliably.

Context

Now AMC reports this on failure, instead of hardfaulting.

I will check if there are more cases of malloc not getting handled, however, this is an important fix already.

@dagar
Copy link
Member

dagar commented Aug 28, 2023

I pushed a fix for the trivial astyle whitespace failure. https://github.com/PX4/PX4-Autopilot/actions/runs/5998073699/job/16265657710?pr=22012

image

Starting a new console allocates memory dynamically, which can fail.
@dagar dagar merged commit af40d5b into main Aug 29, 2023
83 of 86 checks passed
@dagar dagar deleted the pr-nsh_consolemain-enomem branch August 29, 2023 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants