mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-09-24 19:08:21 +08:00
fix(posix): guard px4_task_join/delete against negative task ids
px4_task_t is a plain int and callers hold -1 for "no task" (e.g. dataman's g_task_id after stop). The bounds checks only tested id < PX4_MAX_TASKS, which is true for negative ids, so px4_task_join(-1) and px4_task_delete(-1) would index taskmap[-1] out of bounds. Check id >= 0 as well. Signed-off-by: Julian Oes <julian@oes.ch>
This commit is contained in:
@@ -275,7 +275,7 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
|
||||
|
||||
int px4_task_join(px4_task_t id)
|
||||
{
|
||||
if (id < PX4_MAX_TASKS) {
|
||||
if (id >= 0 && id < PX4_MAX_TASKS) {
|
||||
pthread_mutex_lock(&task_mutex);
|
||||
pthread_t pid = taskmap[id].pid;
|
||||
pthread_mutex_unlock(&task_mutex);
|
||||
@@ -294,7 +294,7 @@ int px4_task_delete(px4_task_t id)
|
||||
pthread_t pid;
|
||||
PX4_DEBUG("Called px4_task_delete");
|
||||
|
||||
if (id < PX4_MAX_TASKS && taskmap[id].isused) {
|
||||
if (id >= 0 && id < PX4_MAX_TASKS && taskmap[id].isused) {
|
||||
pid = taskmap[id].pid;
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user