Skip to content

Commit

Permalink
AP_Scripting: prevent a code path to abort() in scripting
Browse files Browse the repository at this point in the history
if scripting can't find an error handler it can call abort(). We don't
ever want to do that in ArduPilot
  • Loading branch information
tridge committed Feb 21, 2024
1 parent 4ad1231 commit f809737
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libraries/AP_Scripting/lua/src/ldo.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ l_noret luaD_throw (lua_State *L, int errcode) {
lua_unlock(L);
g->panic(L); /* call panic function (last chance to jump out) */
}
abort();
lua_abort();
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions libraries/AP_Scripting/lua_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,4 +956,23 @@ int lua_range_finder_handle_script_msg(lua_State *L) {
}
#endif

/*
lua wants to abort, and doesn't have access to a panic function
*/
void lua_abort()
{
INTERNAL_ERROR(AP_InternalError::error_t::flow_of_control);
#if AP_SIM_ENABLED
AP_HAL::panic("lua_abort called");
#else
if (!hal.util->get_soft_armed()) {
AP_HAL::panic("lua_abort called");
}
// abort while flying, all we can do is loop
while (true) {
hal.scheduler->delay(1000);
}
#endif
}

#endif // AP_SCRIPTING_ENABLED
2 changes: 2 additions & 0 deletions libraries/AP_Scripting/lua_common_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@
#endif // REPL_OUT

int lua_get_current_ref();
void lua_abort(void) __attribute__((noreturn));

0 comments on commit f809737

Please sign in to comment.