Skip to content

Commit

Permalink
uORB: Check that px4_mmap returns a valid pointer
Browse files Browse the repository at this point in the history
If px4_mmap fails, do not proceed and cause random system crash later,
instead produce meaningful error messages from uorb_start().
  • Loading branch information
pussuw committed Oct 11, 2023
1 parent aa9024e commit 312d586
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions platforms/common/uORB/uORBManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
****************************************************************************/

#include <dirent.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/shm.h>
Expand Down Expand Up @@ -102,6 +103,11 @@ bool uORB::Manager::initialize()
if (ftruncate(shm_fd, sizeof(uORB::Manager)) == 0) {
// mmap the shared memory region
void *ptr = px4_mmap(0, sizeof(uORB::Manager), PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);

if (ptr == MAP_FAILED) {
return false;
}

_Instance = new (ptr) uORB::Manager();

for (auto &publisher : _Instance->g_has_publisher) {
Expand Down

0 comments on commit 312d586

Please sign in to comment.