Skip to content

hal: check strstr() results before dereferencing them - #56

Merged
wberube merged 1 commit into
OpenIPC:masterfrom
wjames111:fix/strstr-null
Oct 7, 2026
Merged

wberube merged 1 commit into
OpenIPC:masterfrom
wjames111:fix/strstr-null

Conversation

@wjames111

Copy link
Copy Markdown
Contributor

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.

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.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Guard HAL parsing against missing kernel text

🐞 Bug fix 🕐 Less than 10 minutes

Grey Divider

AI Description

• Prevent crashes when kernel files are empty or omit expected memory, board, or temperature text.
• Require enough board text before copying the package identifier.
Diagram

graph TD
  K["Kernel text files"] --> R{"Read succeeded?"} -->|yes| M{"Token found?"} -->|yes| B{"SSC token?"} -->|yes| L{"Length at least 7?"} -->|yes| P["Update HAL values"]
  B -->|no| P
  R -->|no| D["Keep defaults"]
  M -->|no| D
  L -->|no| D
Loading
High-Level Assessment

Keep the localized guards: they address the three crash paths without changing HAL detection or temperature behavior for valid input. A shared parser would add abstraction for three distinct formats without a clear benefit.

Files changed (1) +16 / -9

Bug fix (1) +16 / -9
support.cGuard kernel-text matches before HAL parsing +16/-9

Guard kernel-text matches before HAL parsing

• Checks that reads succeed and expected tokens are present before parsing LX_MEM and temperature values. Copies the SSC package identifier only when the match contains all required characters, leaving initialized or previously recorded values unchanged otherwise.

src/hal/support.c

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Status shows stale temperatures 🐞 Bug ≡ Correctness
Description
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.
Code

src/hal/support.c[R349-350]

+                if (parsed)
+                    lastReadTemp = strtof(parsed + 12, &remain);
Evidence
The timestamp is set before the file is read, while the added guard skips the only assignment to
lastReadTemp when the marker is absent. Both output paths format the returned cached value without
checking whether this refresh succeeded.

src/hal/support.c[332-352]
src/server.c[1559-1570]
src/region.c[86-94]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## 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


Grey Divider

Tip of the day
💡 Did you know, you can route each severity your way: inline, summary, both, or drop

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread src/hal/support.c
Comment on lines +349 to +350
if (parsed)
lastReadTemp = strtof(parsed + 12, &remain);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

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

@wberube
wberube merged commit b42c7dd into OpenIPC:master Oct 7, 2026
@wberube

wberube commented Oct 7, 2026

Copy link
Copy Markdown
Member

Thank you very much for your contribution!

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.

2 participants