Skip to content

Fix NPE in macOS FFM process backend and harden native struct dereferences - #3526

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:fix/mac-ffm-npe-guards
Jul 26, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:fix/mac-ffm-npe-guards

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Addresses the real findings from the first Coverity Scan of oshi-core-ffm (now captured after the scan was configured to reach the FFM module).

One real bug + one hardening, both in MacOSProcessFFM:

  • Fix NullPointerException (Coverity CID 1673024). The static initializer dereferenced IORegistryEntry.getName() without a guard. getName() is nullable (null segment, native IORegistryEntryGetName failure, or getOrDefault fallback), so a CPU IOPlatformDevice entry with no readable name would throw an ExceptionInInitializerError and render the entire MacOSProcessFFM class unusable. Now guarded, mirroring the existing pattern in MacFirmwareFFM.

  • Harden getpwuid/getgrgid struct dereferences (Coverity CID 1673015). These are safe today — getpwuid/getgrgid convert the native NULL to Java null, and the != null guard admits only real pointers — but the guard was on the raw pointer rather than on the getStructFromNativePointer result actually dereferenced. Moving the guard onto the struct keeps the code correct even if getpwuid/getgrgid ever stop converting NULL to null, and clears the finding at the source.

The remaining Coverity findings in the module were triaged as false positives / intentional (unnamed-variable try (var _ = …) handling, @SuppressWarnings("resource") on borrowed CFAllocatorGetDefault singletons, benign NULL-wrapped getOrDefault defaults, poll() after isEmpty(), and a WMI date FP already accepted on the JNA twin).

Also

Reduce the Coverity Scan schedule from every 4 days to weekly (Saturday 00:00 UTC). Coverity Scan throttles frequent runs on lower-priority projects; weekly is ample, and the workflow can still be dispatched manually after major changes.

Testing

Both sites are native IOKit/libc boundaries with no parse seam, so a fixture test isn't practical; NativeComparisonTest covers JNA/FFM parity. Pre-commit gate (spotless, checkstyle, install, forbiddenapis, javadoc) passes on oshi-core-ffm.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved macOS process information handling to prevent crashes when CPU registry entries or user/group details are unavailable.
    • Added safer fallbacks that display numeric user and group identifiers when name lookups cannot be completed.
  • Chores

    • Updated automated security scanning to run weekly instead of every four days.
  • Documentation

    • Updated the upcoming release changelog with these fixes.

Coverity flagged a null-dereference of IORegistryEntry.getName() in the
MacOSProcessFFM static initializer (CID 1673024). getName() is nullable
(null segment, native IORegistryEntryGetName failure, or getOrDefault
fallback), and the unguarded getName().toLowerCase() call would throw an
ExceptionInInitializerError that breaks the whole class if a CPU device
lacks a readable name. Guard the name before use, mirroring the existing
pattern in MacFirmwareFFM.

Also harden the getpwuid/getgrgid paths in updateAttributes (CID 1673015):
these are safe today because getpwuid/getgrgid convert the native NULL to
Java null and the != null guard admits only real pointers, but the guard
was on the raw pointer rather than the dereferenced struct. Move the guard
onto the getStructFromNativePointer result so the code stays correct even
if getpwuid/getgrgid stop converting NULL to null.

Reduce the Coverity Scan schedule from every 4 days to weekly (Saturday
00:00 UTC); Coverity Scan throttles frequent runs and weekly is ample, with
manual dispatch available after major changes.
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

MacOSProcessFFM adds null checks for CPU registry names and native passwd/group structs, recording the fix in the changelog. The Coverity workflow schedule changes to a weekly Saturday run.

Changes

macOS FFM safety fixes

Layer / File(s) Summary
Guard macOS FFM native lookups
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java, CHANGELOG.md
CPU registry names are checked before matching, and unavailable passwd/group structs fall back to numeric IDs. The changelog records the fix.

Coverity workflow schedule

Layer / File(s) Summary
Set weekly Coverity schedule
.github/workflows/coverity.yaml
The Coverity Scan workflow changes from every four days at 09:00 UTC to Saturdays at 00:00 UTC.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: wolfs

Poem

I’m a rabbit guarding pointers tight,
No null surprise can spoil the night.
CPU names now hop with care,
Users and groups find fallback fare.
Coverity runs beneath Saturday’s moon.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main macOS FFM NPE fix and native struct hardening.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.45%. Comparing base (4879112) to head (9d4772e).

Files with missing lines Patch % Lines
...ain/java/oshi/software/os/mac/MacOSProcessFFM.java 54.54% 0 Missing and 5 partials ⚠️

❌ Your patch check has failed because the patch coverage (54.54%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3526      +/-   ##
============================================
- Coverage     78.51%   78.45%   -0.07%     
+ Complexity     4089     3830     -259     
============================================
  Files           697      697              
  Lines         24106    24108       +2     
  Branches       3993     3994       +1     
============================================
- Hits          18927    18913      -14     
- Misses         2981     2990       +9     
- Partials       2198     2205       +7     
Flag Coverage Δ
linux 35.06% <0.00%> (-0.06%) ⬇️
macos 36.02% <54.54%> (-0.02%) ⬇️
windows 43.28% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CHANGELOG.md`:
- Around line 3-5: Update the “Bug Fixes and Improvements” heading in
CHANGELOG.md to level 2 so it follows the release’s level-1 heading hierarchy.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e4e871ea-602d-407f-8be3-15fab934d2a5

📥 Commits

Reviewing files that changed from the base of the PR and between 4879112 and 9d4772e.

📒 Files selected for processing (3)
  • .github/workflows/coverity.yaml
  • CHANGELOG.md
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout. (7)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2026-05-31T05:53:04.246Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3311
File: .github/workflows/site.yaml:21-21
Timestamp: 2026-05-31T05:53:04.246Z
Learning: When a GitHub Actions workflow verifies that a pinned commit SHA matches a version tag, dereference annotated tags before comparing to a commit SHA. The API `GET /repos/{owner}/{repo}/git/refs/tags/{tag}` returns the tag *object* SHA for annotated tags (not the underlying commit SHA), so comparing it directly to a commit SHA will cause false mismatches. Instead: (1) fetch the tag object SHA via `GET /repos/{owner}/{repo}/git/refs/tags/{tag}`; (2) resolve that tag object to the underlying commit by calling `GET /repos/{owner}/{repo}/git/tags/{tag_object_sha}`; (3) compare the pinned commit SHA to the resolved commit at `.object.sha`.

Applied to files:

  • .github/workflows/coverity.yaml
📚 Learning: 2026-07-21T20:38:16.728Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3509
File: oshi-demo/pom.xml:72-80
Timestamp: 2026-07-21T20:38:16.728Z
Learning: For the OSHI Maven/Jacoco CI workflows, coverage aggregation/report upload steps should run only when the test job succeeds (e.g., guard with conditions like `if: success()`). Do not add logic to generate/upload or preserve aggregate coverage artifacts after test failures, and avoid fragile/over-engineered handling of exit status unless there is an explicit separate project requirement.

Applied to files:

  • .github/workflows/coverity.yaml
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
🪛 markdownlint-cli2 (0.23.0)
CHANGELOG.md

[warning] 3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5

(MD001, heading-increment)

🔇 Additional comments (2)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java (1)

109-118: LGTM!

Also applies to: 281-287, 292-298

.github/workflows/coverity.yaml (1)

6-6: LGTM!

Comment thread CHANGELOG.md Resolved
@dbwiddis
dbwiddis merged commit a99741d into oshi:master Jul 26, 2026
16 checks passed
@dbwiddis
dbwiddis deleted the fix/mac-ffm-npe-guards branch July 26, 2026 01:09
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.

1 participant