Skip to content

[Settings] Fix clearTask() overwriting pins of other tasks - #5672

Merged
TD-er merged 1 commit into
letscontrolit:megafrom
goodprogrammist:bugfix/clearTask-OLD_TaskDeviceID-overflow
Oct 24, 2026
Merged

TD-er merged 1 commit into
letscontrolit:megafrom
goodprogrammist:bugfix/clearTask-OLD_TaskDeviceID-overflow

Conversation

@goodprogrammist

Copy link
Copy Markdown

OLD_TaskDeviceID was shrunk to N_TASKS - 9 elements when its storage was reused for the I2C2/I2C3 settings, but SettingsStruct::clearTask() still does OLD_TaskDeviceID[task] = 0u. For task index 3 and up this writes 4 bytes past the array into TaskDevicePin1..3 / TaskDevicePort of other tasks. clearTask() runs when a task is deleted on the Devices page, when its plugin is changed, and on TaskClear.

On ESP8266 (12 tasks) the damage shows up right away. Example: TaskClear,5 on a unit with a PZEM-004T on task 6 (SW serial RX GPIO1, TX GPIO3) and a switch on task 7 (GPIO16). After the clear, TaskDevicePin1 of tasks 6, 7 and 8 was 0. Nothing changes until the settings are reloaded: after the next reboot the PZEM read on GPIO0 and returned NaN, and the switch read GPIO0 (always high). Downgrading the firmware did not help, because the bad values were already in config.dat. On ESP32 (32 tasks) the same happens for task index 23 and up.

The array is unused (its comment already says so), so this PR removes the write.

Validation:

  • Host harness with the same member layout (N_TASKS = 12): before the fix, clearTask(t) changes pins of other tasks for every t >= 3 (31 bytes in total), and -fsanitize=bounds reports index 3 out of bounds for type 'unsigned int [3]'. After the fix, no foreign pin bytes change.
  • Built normal_ESP8266_4M1M (Arduino core 3.1.2) with this change.
  • On an ESP8266 with the fixed build, TaskClear on task 7: TaskDevicePin1..3 / TaskDevicePort of all other tasks in config.dat stayed the same.

OLD_TaskDeviceID only has N_TASKS - 9 elements, but clearTask() still wrote
OLD_TaskDeviceID[task]. For task index 3 and up this writes past the array
into TaskDevicePin1..3/TaskDevicePort of other tasks. The array is unused, so
the write is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TD-er

TD-er commented Oct 24, 2026

Copy link
Copy Markdown
Member

Good find!

@TD-er
TD-er merged commit ebaf41e into letscontrolit:mega Oct 24, 2026
@tonhuisman

Copy link
Copy Markdown
Contributor

I already took care of this in #5522 but that hasn't been merged yet. It was kind of a 'hidden' fix 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants