Skip to content

sys/pthread: check return value of malloc()#12511

Merged
benpicco merged 1 commit into
RIOT-OS:masterfrom
benpicco:pthread-malloc_check
Oct 20, 2019
Merged

sys/pthread: check return value of malloc()#12511
benpicco merged 1 commit into
RIOT-OS:masterfrom
benpicco:pthread-malloc_check

Conversation

@benpicco

Copy link
Copy Markdown
Contributor

Contribution description

To prevent a NULL pointer dereference on a memory constrained system, check if malloc() was actually successful before carrying on.

Testing procedure

Flash one of the tests/pthread* on a memory constrained device.
Without this patch you will observe a hard fault.

Issues/PRs references

discovered on #12433

@benpicco benpicco added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: POSIX Area: POSIX API wrapper Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer labels Oct 19, 2019
@benpicco benpicco force-pushed the pthread-malloc_check branch from 9bcc560 to 693889b Compare October 19, 2019 16:54
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Oct 19, 2019
Comment thread sys/posix/pthread/pthread.c

@maribu maribu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK. I'm 100% sure that the added error handleding is not breaking anything.

To prevent a NULL pointer dereference on a memory constrained system,
check if malloc() was actually successful.
@benpicco benpicco force-pushed the pthread-malloc_check branch from 496d286 to 764a9e9 Compare October 20, 2019 12:17
@benpicco benpicco merged commit c9e7fff into RIOT-OS:master Oct 20, 2019
@benpicco benpicco deleted the pthread-malloc_check branch October 20, 2019 18:40
@fjmolinas fjmolinas added this to the Release 2020.01 milestone Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: POSIX Area: POSIX API wrapper CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants