Sub-IoT / Sub-IoT-Stack

Sub-IoT: Open Source Stack for Dash7 Alliance Protocol
https://sub-iot.github.io/Sub-IoT-Stack/
Other
150 stars 90 forks source link

sched_register_task() may register too many tasks #108

Closed sjorsdewit closed 3 years ago

sjorsdewit commented 3 years ago

sched_register_task() checks if NUM_TASKS is reached. It seems there is an off-by-one in this check:

The bug

If NG(num_registered_tasks) == NUM_TASKS, no further tasks should be register-able, as all available slots are already claimed. The current implementation returns SUCCESS and results in the situation NG(num_registered_tasks) == (NUM_TASKS+1). This also means that the arrays NG(m_index) and NG(m_info) are accessed out-of-bounds (indexed one past the end).

How to reproduce

Impact

This only impacts firmwares that try to register exactly one task too many, which is probably fairly rare (but can be hard to debug).

LOorts-Aloxy commented 3 years ago

Thank you for the pull request! It seems this is indeed a problem in the code.

LOorts-Aloxy commented 3 years ago

Thank you for your pull request @sjorsdewit, this can prevent a lot of weird behavior! :+1: