Repository navigation
hal: check strstr() results before dereferencing them - #56
Conversation
hal_identify() and hal_temperature_read() search text read from kernel files (/proc/cmdline for LX_MEM=, /sys/devices/soc0/machine for SSC, the msys TEMP_R node for "Temperature ") and use the result without checking it. When a node is missing, empty or worded differently, strstr() returns NULL and divinus segfaults during identification, or on GET /api/status in the temperature case. Only use each value when the read succeeded and the match was found, and make sure the SSC match is long enough for the three characters copied out of it.
PR Summary by QodoGuard HAL parsing against missing kernel text
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1. Status shows stale temperatures
|
| if (parsed) | ||
| lastReadTemp = strtof(parsed + 12, &remain); |
There was a problem hiding this comment.
1. Status shows stale temperatures 🐞 Bug ≡ Correctness
hal_temperature_read() leaves lastReadTemp unchanged when the new parsed guard rejects a line, even though it has already advanced lastMillisTemp. If TEMP_R stops containing Temperature after a successful reading, /api/status and the temperature overlay keep displaying the old value until a valid reading returns.
Agent Prompt
## Issue description
A missing temperature marker leaves the previous reading cached and visible as current.
## Fix Focus Areas
- src/hal/support.c[332-352]
- src/server.c[1559-1570]
- src/region.c[86-94]
## Recommended Fix
On an unsuccessful temperature read or parse, invalidate the cached value rather than retaining the previous reading. Have status and overlay formatting display an unavailable value when no valid temperature exists; only mark a reading fresh after a successful parse.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Thank you very much for your contribution! |
hal_identify() and hal_temperature_read() search text read from kernel
files (/proc/cmdline for LX_MEM=, /sys/devices/soc0/machine for SSC,
the msys TEMP_R node for "Temperature ") and use the result without
checking it. When a node is missing, empty or worded differently,
strstr() returns NULL and divinus segfaults during identification, or
on GET /api/status in the temperature case.
Only use each value when the read succeeded and the match was found,
and make sure the SSC match is long enough for the three characters
copied out of it.
Built for infinity6e (SSC338Q). We've been running this fix on SSC338Q units.