Repository navigation
Fix NPE in macOS FFM process backend and harden native struct dereferences - #3526
Conversation
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.
📝 WalkthroughWalkthroughMacOSProcessFFM 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. ChangesmacOS FFM safety fixes
Coverity workflow schedule
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report❌ Patch coverage is
❌ 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
.github/workflows/coverity.yamlCHANGELOG.mdoshi-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!
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 dereferencedIORegistryEntry.getName()without a guard.getName()is nullable (null segment, nativeIORegistryEntryGetNamefailure, orgetOrDefaultfallback), so a CPUIOPlatformDeviceentry with no readable name would throw anExceptionInInitializerErrorand render the entireMacOSProcessFFMclass unusable. Now guarded, mirroring the existing pattern inMacFirmwareFFM.Harden
getpwuid/getgrgidstruct dereferences (Coverity CID 1673015). These are safe today —getpwuid/getgrgidconvert the nativeNULLto Javanull, and the!= nullguard admits only real pointers — but the guard was on the raw pointer rather than on thegetStructFromNativePointerresult actually dereferenced. Moving the guard onto the struct keeps the code correct even ifgetpwuid/getgrgidever stop convertingNULLtonull, 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 borrowedCFAllocatorGetDefaultsingletons, benign NULL-wrappedgetOrDefaultdefaults,poll()afterisEmpty(), 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;
NativeComparisonTestcovers JNA/FFM parity. Pre-commit gate (spotless, checkstyle, install, forbiddenapis, javadoc) passes onoshi-core-ffm.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Chores
Documentation