Skip to content

Fix parsing/bounds guards and Unix session consistency (JNA/FFM) - #3484

Merged
dbwiddis merged 8 commits into
oshi:masterfrom
dbwiddis:parse-portability-audit-fixes
Jul 18, 2026
Merged

dbwiddis merged 8 commits into
oshi:masterfrom
dbwiddis:parse-portability-audit-fixes

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 18, 2026 •

Copy link
Copy Markdown
Member

Final batch of pre-7.4.1 audit fixes: parsing/bounds guards plus two Unix backend consistency fixes.

Crash / bounds guards (oshi-common)

  • ParseUtil.getStringBetween threw StringIndexOutOfBoundsException when the delimiter occurred exactly once (a truncated line like key = 'value), propagating through the *nix HAL string parsers. Now returns "" when the delimiter is absent or unmatched. (regression test added)
  • AbstractCentralProcessor.getSystemCpuLoadBetweenTicks(long[], long[]) threw ArrayIndexOutOfBoundsException on mismatched array lengths where the interface documents IllegalArgumentException; it now validates lengths up front like its sibling overloads.
  • Prtvtoc (Solaris disk) checked split.length > 0 but read split[1]; corrected to > 1.

JNA↔FFM consistency (Unix)

  • FreeBSD & Solaris Who decoded 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.
  • Solaris FFM getSessions had no override, so it used the who command while JNA reads the native utmpx database (different session fields). Added 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 layout mirrors the JNA SolarisUtmpx struct and its offsets were verified locally; the illumos CI NativeComparisonTest (JNA==FFM) is the runtime validation.

Summary by CodeRabbit

  • New Features

    • Added Solaris session enumeration via the FFM backend, with automatic fallback to existing session reporting when needed.
  • Bug Fixes

    • Hardened string parsing when delimiters are missing or only partially present.
    • Added input validation for CPU tick arrays to prevent incorrect load calculations.
    • Fixed Solaris partition parsing for incomplete sector tokens.
    • Updated FreeBSD and Solaris session decoding to use UTF-8 for user/device/host details.
  • Refactor

    • Improved fixed-width native string decoding for FFM-based readers.
  • Tests

    • Extended parsing tests to cover delimiter edge cases.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8d007aef-08f4-47d7-b9b3-1bd3b5c8565f

📥 Commits

Reviewing files that changed from the base of the PR and between 650a852 and deeddbf.

📒 Files selected for processing (14)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/disk/Prtvtoc.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/driver/mac/WhoFFM.java
  • oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/WhoFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/unix/freebsd/Who.java
  • oshi-core/src/main/java/oshi/driver/unix/solaris/Who.java
🚧 Files skipped from review as they are similar to previous changes (7)
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/disk/Prtvtoc.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/driver/unix/freebsd/Who.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/WhoFFM.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 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/src/main/java/oshi/driver/unix/solaris/Who.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/driver/mac/WhoFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
📚 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/util/ParseUtil.java
🔇 Additional comments (7)
oshi-common/src/main/java/oshi/util/ParseUtil.java (1)

664-670: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java (1)

20-20: LGTM!

Also applies to: 441-459

oshi-core-ffm/src/main/java/oshi/driver/mac/WhoFFM.java (1)

10-10: LGTM!

Also applies to: 60-62

oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/FreeBsdLibcFunctions.java (1)

220-220: LGTM!

Also applies to: 230-230, 240-240

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

16-16: LGTM!

Also applies to: 266-266

oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java (1)

8-11: LGTM!

Also applies to: 153-286

oshi-core/src/main/java/oshi/driver/unix/solaris/Who.java (1)

47-49: LGTM!


📝 Walkthrough

Walkthrough

This change adds Solaris FFM utmpx session enumeration, switches native session fields to UTF-8 decoding, and hardens delimiter, partition, and CPU tick-array validation with corresponding tests and changelog documentation.

Changes

Native session handling

Layer / File(s) Summary
Fixed-width native string decoding
oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java, oshi-core-ffm/src/main/java/oshi/driver/*/WhoFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/freebsd/*, oshi-core-ffm/src/main/java/oshi/software/os/mac/*
Adds UTF-8, NUL-terminated fixed-width decoding and applies it to session and process fields.
Solaris utmpx FFM bindings and collection
oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/*, oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/*, oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/*
Defines Solaris utmpx bindings, enumerates and validates sessions, and selects FFM or command-based retrieval.
JNA session decoding
oshi-core/src/main/java/oshi/driver/unix/{freebsd,solaris}/Who.java
Decodes utmpx user, device, and host fields as UTF-8.

Parsing and input validation hardening

Layer / File(s) Summary
Delimiter and partition parsing guards
oshi-common/src/main/java/oshi/util/ParseUtil.java, oshi-common/src/main/java/oshi/driver/common/unix/solaris/disk/Prtvtoc.java, oshi-common/src/test/java/oshi/util/ParseUtilTest.java, CHANGELOG.md
Handles absent or unmatched delimiters safely, requires a bytes-per-sector field before parsing, and records delimiter edge-case coverage.
CPU tick array length validation
oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
Throws IllegalArgumentException when CPU tick arrays have unexpected lengths.

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
Loading

Possibly related PRs

  • oshi/oshi#3104: Related macOS FFM utmpx migration and fixed-width session string decoding.
  • oshi/oshi#3473: Related macOS who and utmpx UTF-8 decoding changes.

Poem

I’m a rabbit with patches tucked neat,
UTF-8 hops make strings complete.
Ticks align and quotes behave,
Solaris sessions cross the wave.
Bytes find bounds, the logs now sing!

🚥 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 themes: parsing/bounds safeguards and Unix session consistency across JNA/FFM.
Docstring Coverage ✅ Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%.
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 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 56.75676% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.02%. Comparing base (d148fec) to head (deeddbf).

Files with missing lines Patch % Lines
...src/main/java/oshi/driver/unix/solaris/WhoFFM.java 60.00% 4 Missing and 4 partials ⚠️
...re/src/main/java/oshi/driver/unix/freebsd/Who.java 0.00% 3 Missing ⚠️
...oshi/hardware/common/AbstractCentralProcessor.java 0.00% 1 Missing and 1 partial ⚠️
.../oshi/driver/common/unix/solaris/disk/Prtvtoc.java 0.00% 0 Missing and 1 partial ⚠️
...ain/java/oshi/software/os/mac/MacOSProcessFFM.java 0.00% 1 Missing ⚠️
...are/os/unix/solaris/SolarisOperatingSystemFFM.java 0.00% 0 Missing and 1 partial ⚠️

❌ 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     
Flag Coverage Δ
freebsd 27.73% <8.10%> (-0.02%) ⬇️
linux 32.27% <8.10%> (-0.04%) ⬇️
macos 32.82% <16.21%> (-0.08%) ⬇️
openbsd 27.01% <8.10%> (-0.04%) ⬇️
solaris 29.58% <48.64%> (+0.01%) ⬆️
windows 40.86% <8.10%> (-0.02%) ⬇️

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

📥 Commits

Reviewing files that changed from the base of the PR and between 99a15e1 and 650a852.

📒 Files selected for processing (10)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/disk/Prtvtoc.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/test/java/oshi/util/ParseUtilTest.java
  • oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/WhoFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/solaris/SolarisLibcFunctions.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/unix/freebsd/Who.java
  • oshi-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.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-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.java
  • oshi-core/src/main/java/oshi/driver/unix/solaris/Who.java
  • oshi-core/src/main/java/oshi/driver/unix/freebsd/Who.java
  • oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/WhoFFM.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemFFM.java
  • oshi-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!

Comment on lines +42 to +65
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();
}

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.

🩺 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.

dbwiddis added 8 commits July 18, 2026 13:08
…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.
@dbwiddis
dbwiddis force-pushed the parse-portability-audit-fixes branch from 650a852 to deeddbf Compare July 18, 2026 20:10
@dbwiddis
dbwiddis merged commit 81d0c35 into oshi:master Jul 18, 2026
31 of 32 checks passed
@dbwiddis
dbwiddis deleted the parse-portability-audit-fixes branch July 18, 2026 20:57
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