Skip to content

Commit

Permalink
mavlink: fixed nullptr dereferencing in case unknown mavlink message is
Browse files Browse the repository at this point in the history
forwarded

Signed-off-by: Roman <[email protected]>
  • Loading branch information
RomanBapst authored and bkueng committed Jul 27, 2018
1 parent 462cf13 commit 37f59ad
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/modules/mavlink/mavlink_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,20 @@ Mavlink::forward_message(const mavlink_message_t *msg, Mavlink *self)
if (inst != self) {
const mavlink_msg_entry_t *meta = mavlink_get_msg_entry(msg->msgid);

// Extract target system and target component if set
int target_system_id = (meta->target_system_ofs != 0) ? ((uint8_t *)msg)[meta->target_system_ofs] : 0;
int target_component_id = (meta->target_component_ofs != 0) ? ((uint8_t *)msg)[meta->target_component_ofs] : 233;
int target_system_id = 0;
int target_component_id = 233;

// might be nullptr if message is unknown
if (meta) {
// Extract target system and target component if set
if (meta->target_system_ofs != 0) {
target_system_id = ((uint8_t *)msg)[meta->target_system_ofs];
}

if (meta->target_component_ofs != 0) {
target_component_id = ((uint8_t *)msg)[meta->target_component_ofs];
}
}

// Broadcast or addressing this system and not trying to talk
// to the autopilot component -> pass on to other components
Expand Down

0 comments on commit 37f59ad

Please sign in to comment.