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

Fixed null ptr deref of terrain on rover with OSD support #17117

Merged
merged 4 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions libraries/AP_Frsky_Telem/AP_Frsky_SPort_Passthrough.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ bool AP_Frsky_SPort_Passthrough::is_packet_ready(uint8_t idx, bool queue_empty)
{
packet_ready = false;
#if AP_TERRAIN_AVAILABLE
const AP_Terrain &terrain = AP::terrain();
packet_ready = terrain.enabled();
const AP_Terrain *terrain = AP::terrain();
packet_ready = terrain && terrain->enabled();
#endif
}
break;
Expand Down Expand Up @@ -638,12 +638,12 @@ uint32_t AP_Frsky_SPort_Passthrough::calc_terrain(void)
{
uint32_t value = 0;
#if AP_TERRAIN_AVAILABLE
AP_Terrain &terrain = AP::terrain();
if (!terrain.enabled()) {
AP_Terrain *terrain = AP::terrain();
if (terrain == nullptr || !terrain->enabled()) {
return value;
}
float height_above_terrain;
if (terrain.height_above_terrain(height_above_terrain, true)) {
if (terrain->height_above_terrain(height_above_terrain, true)) {
// vehicle height above terrain
value |= prep_number(roundf(height_above_terrain * 10), 3, 2);
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_OSD/AP_OSD_Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1934,10 +1934,10 @@ void AP_OSD_Screen::draw_vtx_power(uint8_t x, uint8_t y)
#if AP_TERRAIN_AVAILABLE
void AP_OSD_Screen::draw_hgt_abvterr(uint8_t x, uint8_t y)
{
AP_Terrain &terrain = AP::terrain();
AP_Terrain *terrain = AP::terrain();

float terrain_altitude;
if (terrain.height_above_terrain(terrain_altitude,true)) {
if (terrain != nullptr && terrain->height_above_terrain(terrain_altitude,true)) {
backend->write(x, y, terrain_altitude < osd->warn_terr, "%4d%c", (int)u_scale(ALTITUDE, terrain_altitude), u_icon(ALTITUDE));
} else {
backend->write(x, y, false, " ---%c", u_icon(ALTITUDE));
Expand Down
4 changes: 2 additions & 2 deletions libraries/AP_Terrain/AP_Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ bool AP_Terrain::allocate(void)

namespace AP {

AP_Terrain &terrain()
AP_Terrain *terrain()
{
return *AP_Terrain::get_singleton();
return AP_Terrain::get_singleton();
}

};
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_Terrain/AP_Terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class AP_Terrain {
};

namespace AP {
AP_Terrain &terrain();
AP_Terrain *terrain();
};

#endif // AP_TERRAIN_AVAILABLE
Expand Down
2 changes: 1 addition & 1 deletion libraries/SITL/SIM_Aircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Aircraft::Aircraft(const char *frame_str) :
sitl->ahrs_rotation_inv = sitl->ahrs_rotation.transposed();
}

terrain = &AP::terrain();
terrain = AP::terrain();

// init rangefinder array to -1 to signify no data
for (uint8_t i = 0; i < RANGEFINDER_MAX_INSTANCES; i++){
Expand Down
4 changes: 2 additions & 2 deletions libraries/SITL/SIM_Ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ void ShipSim::send_report(void)
bool have_alt = false;

#if AP_TERRAIN_AVAILABLE
auto &terrain = AP::terrain();
auto terrain = AP::terrain();
float height;
if (terrain.enabled() && terrain.height_amsl(loc, height, true)) {
if (terrain != nullptr && terrain->enabled() && terrain->height_amsl(loc, height, true)) {
alt = height * 1000;
have_alt = true;
}
Expand Down