Repository navigation
Fix parsing/bounds guards and Unix session consistency (JNA/FFM) - #3484
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (14)
🚧 Files skipped from review as they are similar to previous changes (7)
📜 Recent review details⏰ Context from checks skipped due to timeout. (9)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
🔇 Additional comments (7)
📝 WalkthroughWalkthroughThis change adds Solaris FFM ChangesNative session handling
Parsing and input validation hardening
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant SolarisOperatingSystemFFM
participant WhoFFM
participant SolarisLibcFunctions
participant ExistingWho
SolarisOperatingSystemFFM->>WhoFFM: queryUtxent()
WhoFFM->>SolarisLibcFunctions: setutxent() and getutxent()
SolarisLibcFunctions-->>WhoFFM: utmpx fields and login time
WhoFFM->>WhoFFM: filter and validate sessions
WhoFFM-->>SolarisOperatingSystemFFM: OSSession list
WhoFFM->>ExistingWho: queryWho() on failure
Possibly related PRs
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 (56.75%) 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 #3484 +/- ##
============================================
- Coverage 75.05% 75.02% -0.04%
Complexity 76 76
============================================
Files 590 591 +1
Lines 21559 21583 +24
Branches 3610 3614 +4
============================================
+ Hits 16182 16192 +10
- Misses 3406 3412 +6
- Partials 1971 1979 +8
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: 3
🤖 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
`@oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java`:
- Around line 222-225: Update the array validation in the processor tick
calculation method around the oldTicks and ticks length check to require both
arrays to equal TickType.values().length. Reject any short or oversized array
with IllegalArgumentException, while preserving the existing mismatch validation
behavior and subsequent tick calculations for correctly sized arrays.
In `@oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/WhoFFM.java`:
- Around line 42-65: Update WhoFFM.queryUtxent to synchronize its
setutxent/getutxent/endutxent sequence on the same shared lock used by the JNA
Solaris implementation, such as oshi.driver.unix.solaris.Who.class. Keep the
entire native enumeration, including cleanup and fallback handling, within that
shared synchronization scope.
In
`@oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java`:
- Around line 252-273: Update utmpxUser, utmpxLine, and utmpxHost to decode
their fixed-width native fields with a bounded scan that stops at the first NUL
or the respective field-size limit. Avoid unbounded getString(0) behavior when a
field is exactly full, and preserve the existing UTF-8 decoding and field
offsets.
🪄 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
Run ID: ee6b1c10-2ccb-429e-a449-02b3bed741c2
📒 Files selected for processing (10)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/unix/solaris/disk/Prtvtoc.javaoshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.javaoshi-common/src/main/java/oshi/util/ParseUtil.javaoshi-common/src/test/java/oshi/util/ParseUtilTest.javaoshi-core-ffm/src/main/java/oshi/driver/unix/solaris/WhoFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemFFM.javaoshi-core/src/main/java/oshi/driver/unix/freebsd/Who.javaoshi-core/src/main/java/oshi/driver/unix/solaris/Who.java
📜 Review details
⏰ Context from checks skipped due to timeout. (12)
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 26, ubuntu-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: Test JDK 26, macos-latest
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Test JDK 21, ubuntu-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/driver/common/unix/solaris/disk/Prtvtoc.javaoshi-common/src/main/java/oshi/util/ParseUtil.javaoshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
📚 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-common/src/main/java/oshi/driver/common/unix/solaris/disk/Prtvtoc.javaoshi-core/src/main/java/oshi/driver/unix/solaris/Who.javaoshi-core/src/main/java/oshi/driver/unix/freebsd/Who.javaoshi-core-ffm/src/main/java/oshi/driver/unix/solaris/WhoFFM.javaoshi-common/src/main/java/oshi/util/ParseUtil.javaoshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
🔇 Additional comments (9)
oshi-common/src/main/java/oshi/util/ParseUtil.java (1)
664-670: LGTM!oshi-common/src/test/java/oshi/util/ParseUtilTest.java (1)
367-369: LGTM!oshi-common/src/main/java/oshi/driver/common/unix/solaris/disk/Prtvtoc.java (1)
44-44: LGTM!CHANGELOG.md (1)
16-16: LGTM!oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java (1)
8-11: LGTM!Also applies to: 153-251, 276-286
oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/WhoFFM.java (1)
1-41: LGTM!Also applies to: 66-71
oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemFFM.java (1)
8-15: LGTM!Also applies to: 25-25, 96-100
oshi-core/src/main/java/oshi/driver/unix/freebsd/Who.java (1)
47-49: LGTM!oshi-core/src/main/java/oshi/driver/unix/solaris/Who.java (1)
47-49: LGTM!
| public static synchronized List<OSSession> queryUtxent() { | ||
| List<OSSession> whoList = new ArrayList<>(); | ||
| try (Arena arena = Arena.ofConfined()) { | ||
| setutxent(); | ||
| try { | ||
| MemorySegment utPtr; | ||
| while ((utPtr = getutxent()) != null) { | ||
| MemorySegment ut = utPtr.reinterpret(UTMPX_LAYOUT.byteSize(), arena, null); | ||
| short type = utmpxType(ut); | ||
| if (type == USER_PROCESS || type == LOGIN_PROCESS) { | ||
| String user = utmpxUser(ut); | ||
| String device = utmpxLine(ut); | ||
| String host = utmpxHost(ut); | ||
| long loginTime = utmpxLoginTime(ut); | ||
| // Sanity check. If errors, default to who command line | ||
| if (!isSessionValid(user, device, loginTime)) { | ||
| return oshi.util.driver.unix.Who.queryWho(); | ||
| } | ||
| whoList.add(new OSSession(user, device, loginTime, host)); | ||
| } | ||
| } | ||
| } finally { | ||
| endutxent(); | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Synchronize JNA and FFM enumeration on the same lock.
The two public Solaris implementations use different class monitors while operating on libc’s shared utmpx cursor. Concurrent JNA/FFM calls can rewind, advance, or close each other’s iteration, producing incomplete sessions. Use a shared lock, such as oshi.driver.unix.solaris.Who.class, around this native sequence.
🤖 Prompt for 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.
In `@oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/WhoFFM.java` around
lines 42 - 65, Update WhoFFM.queryUtxent to synchronize its
setutxent/getutxent/endutxent sequence on the same shared lock used by the JNA
Solaris implementation, such as oshi.driver.unix.solaris.Who.class. Keep the
entire native enumeration, including cleanup and fallback handling, within that
shared synchronization scope.
…limiter A line containing the delimiter exactly once (e.g. a truncated "key = 'value") made substring(firstOcc + 1, lastIndexOf) cross its indexes and throw an uncaught StringIndexOutOfBoundsException through the *nix HAL string parsers. Return "" when the delimiter is absent or appears only once.
…mCpuLoadBetweenTicks The two-argument overload iterated ticks.length and indexed oldTicks, throwing ArrayIndexOutOfBoundsException on mismatched lengths where the interface documents IllegalArgumentException. Validate the lengths up front, matching the sibling overloads.
The guard checked split.length > 0 but read split[1]; a degenerate header line would satisfy the guard and throw ArrayIndexOutOfBoundsException. Require length > 1 to match the accessed index.
The JNA Who drivers decoded ut_user/ut_line/ut_host as US-ASCII while the FFM backend uses UTF-8, so any byte >= 0x80 produced different session strings. Decode as UTF-8, matching FFM and the macOS alignment from #3473.
SolarisOperatingSystemFFM had no getSessions override, so it fell back to the who command while the JNA backend reads the native utmpx database, yielding different session host/time fields. Add getutxent/setutxent/endutxent bindings and a Solaris utmpx StructLayout to SolarisLibcFunctions, a Solaris WhoFFM mirroring the JNA driver, and a getSessions override honoring USE_WHO_COMMAND. The utmpx layout mirrors the JNA SolarisUtmpx struct (validated by the JNA==FFM comparison test on the illumos CI runner).
The two-argument overload only checked the two arrays against each other, so two equal-but-short arrays passed validation and then threw ArrayIndexOutOfBounds at ticks[IOWAIT.getIndex()]. Require both arrays to equal TickType.values().length, matching the single-argument overload.
…oding Reading a fixed-width native char field with asSlice(offset,size).getString(0) requires a NUL within the field; a value that exactly fills the field carries none, so getString scans past it (IndexOutOfBoundsException). Add ForeignFunctions.readFixedWidthString, which decodes as UTF-8 up to the first NUL or the field width (matching JNA's Native.toString), and use it for every fixed-width field read: the Solaris/FreeBSD/macOS utmpx user, line, and host fields, and the macOS process pbi_comm name.
650a852 to
deeddbf
Compare
Final batch of pre-7.4.1 audit fixes: parsing/bounds guards plus two Unix backend consistency fixes.
Crash / bounds guards (oshi-common)
ParseUtil.getStringBetweenthrewStringIndexOutOfBoundsExceptionwhen the delimiter occurred exactly once (a truncated line likekey = 'value), propagating through the *nix HAL string parsers. Now returns""when the delimiter is absent or unmatched. (regression test added)AbstractCentralProcessor.getSystemCpuLoadBetweenTicks(long[], long[])threwArrayIndexOutOfBoundsExceptionon mismatched array lengths where the interface documentsIllegalArgumentException; it now validates lengths up front like its sibling overloads.Prtvtoc(Solaris disk) checkedsplit.length > 0but readsplit[1]; corrected to> 1.JNA↔FFM consistency (Unix)
Whodecoded utmpx session strings as US-ASCII while FFM uses UTF-8 — now UTF-8, matching FFM and the macOS alignment from Fix macOS JNA-backend divergences from the FFM backend #3473.getSessionshad no override, so it used thewhocommand while JNA reads the native utmpx database (different session fields). Addedgetutxent/setutxent/endutxentbindings and a SolarisutmpxStructLayouttoSolarisLibcFunctions, a SolarisWhoFFMmirroring the JNA driver, and agetSessionsoverride honoringUSE_WHO_COMMAND. The layout mirrors the JNASolarisUtmpxstruct and its offsets were verified locally; the illumos CINativeComparisonTest(JNA==FFM) is the runtime validation.Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests