From 4e83e993161d43f4f6ba8a4ab10fc950f58d5f64 Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Sun, 10 May 2026 20:26:05 +0200 Subject: [PATCH] Fix null pointer dereferences in SettingsScreen index helpers lowBatIndex(), autoOffIndex(), gpsIntervalIndex() each called getNodePrefs() independently without null check, while renderItem() had its own guarded copy. Added null checks consistent with the rest of the class. Also initialize _node_prefs to NULL in UITask constructor. Co-Authored-By: Claude Sonnet 4.6 --- examples/companion_radio/ui-new/UITask.cpp | 19 +++++++++++-------- examples/companion_radio/ui-new/UITask.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 6381c7fe..44676a3b 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -116,10 +116,11 @@ class SettingsScreen : public UIScreen { static const int BATT_DISPLAY_COUNT = 3; int lowBatIndex() { - uint16_t v = _task->getNodePrefs()->low_batt_mv; + NodePrefs* p = _task->getNodePrefs(); + if (!p) return 0; for (int i = 0; i < LOW_BAT_COUNT; i++) - if (LOW_BAT_OPTS[i] == v) return i; - return 0; // default: off + if (LOW_BAT_OPTS[i] == p->low_batt_mv) return i; + return 0; } void renderBar(DisplayDriver& display, int x, int y, int value, int max_val) { @@ -132,17 +133,19 @@ class SettingsScreen : public UIScreen { } int autoOffIndex() { - uint16_t v = _task->getNodePrefs()->auto_off_secs; + NodePrefs* p = _task->getNodePrefs(); + if (!p) return 1; for (int i = 0; i < AUTO_OFF_COUNT; i++) - if (AUTO_OFF_OPTS[i] == v) return i; - return 1; // default: 15s + if (AUTO_OFF_OPTS[i] == p->auto_off_secs) return i; + return 1; } #if ENV_INCLUDE_GPS == 1 int gpsIntervalIndex() { - uint32_t v = _task->getNodePrefs()->gps_interval; + NodePrefs* p = _task->getNodePrefs(); + if (!p) return 0; for (int i = 0; i < GPS_INTERVAL_COUNT; i++) - if (GPS_INTERVAL_OPTS[i] == v) return i; + if (GPS_INTERVAL_OPTS[i] == p->gps_interval) return i; return 0; } #endif diff --git a/examples/companion_radio/ui-new/UITask.h b/examples/companion_radio/ui-new/UITask.h index 05158773..5447270e 100644 --- a/examples/companion_radio/ui-new/UITask.h +++ b/examples/companion_radio/ui-new/UITask.h @@ -68,7 +68,7 @@ class UITask : public AbstractUITask { public: - UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) { + UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL), _node_prefs(NULL) { next_batt_chck = _next_refresh = 0; ui_started_at = 0; _batt_mv = 0;